Sys.setenv(SPOTIFY_CLIENT_ID = 'YOUR_CLIENT_ID')
Sys.setenv(SPOTIFY_CLIENT_SECRET = 'YOUR_CLIENT_SECRET')
access_token <- get_spotify_access_token()Spotify API
Introduction
Music is a large part of my daily schedule, and Spotify allows me to explore data involving this music. Curious people who love music would be inclined to use this.
Setting up API
Log in to your Spotify account
Log into the dashboard (select “dashboard” )
Select the “Create an App” button
Enter the information necessary
Create the App
Go to Settings, view “Client Secret”
This will hold the Client ID and Secret needed to use Spotify API
Packages
These packages will assist us in our search for the information we want.
Accessing API in R
These lines of code call our API, and allows us to work with the data that we want to.
Using Spotify API
I want to see what the most popular songs are for one of my favorite bands, Nirvana. Fortunately, we are able to do this using the data.
get_artist_top_tracks(
'6olE6TJLqED3rqDCT0FyPh', #nirvana ID
market = "US",
authorization = get_spotify_access_token(),
include_meta_info = FALSE
) %>% select(name, popularity) name popularity
1 Smells Like Teen Spirit 80
2 Come As You Are 79
3 Heart-Shaped Box 82
4 About A Girl 78
5 Lithium 73
6 Something In The Way 72
7 Dumb 78
8 The Man Who Sold The World - Live 78
9 All Apologies 76
10 In Bloom 71
As we can see, their songs Smells Like Teen Spirit, Come As You Are, and Heart-Shaped Box are among the most popular Nirvana records.
With an awesome tool like this, we can find lots of information about all things music!