Spotify
Spotifyr API Tutorial
Spotifyr is an R package for pulling information from Spotify’s web API. Spotifyr allows you to pull information from specific artists, such as all audio features and lots of specific track/album metrics. It also allows you to pull song and playlist information for yourself as well as recommendations based on your previous listening history.
Authentication
First you want to sign into your spotify account or create an account to set up a Spotify Dev account here
Once you’ve logged in, click on create app and enter your app descriptions based on your needs.
Finally, once the app is set up, click on settings. This will show you your client id and client secret that you will need for the spotifyr package.
Installation
First install and load in the spotifyr package in R.
`Install.packages("spotifyr")`
library(spotifyr)
Next, you want to set your own credentials into the R environment using the variables client_id and client_secret. You also want to set your spotify access token using the variable access_token. Once you’ve done this you can use the Spotify API.
``client_id<-"xxxxxxxxxxxxxxxx"
client_secret<-"xxxxxxxxxxxx"
access_token <- get_spotify_access_token()
Sys.setenv(SPOTIFY_CLIENT_ID = client_id)
Sys.setenv(SPOTIFY_CLIENT_SECRET = client_secret)``
Demonstration
Here is an example using the spotifyr package to call all of the songs by Drake.
``drake <- get_artist_audio_features('Drake')``
You can also get recommendations of artists to listen to based on a specific artist, song or playlist that you like. Below shows how you can get a recommendation of artists you might like based on Drake.
`artist_id <- "3TVXtAsR1Inumwj472S9r4". #Drakes Artist ID
recommendations <- get_related_artists(artist_id) %>% select(name, uri)`