Why use Spotify API

Spotify is a music streaming platform that allows listeners to play music of there choice while also deciding the music they like, dislike, or want to hear more of! Accessing the developer tools through (https://developer.spotify.com/dashboard/login) will allow for the gathering of data that can be used to analyze data for further understanding and studies.

Setting Up

You need to install and load the “spotifyr” package. Once you have downloaded the package within R and accessed the developer tools, you can use you client ID and your client secret to “login”.

Sys.setenv(SPOTIFY_CLIENT_ID = ‘PASTE CLIENT ID’) Sys.setenv(SPOTIFY_CLIENT_SECRET = ‘PASTE CLIENT SECRET’)

Once you are logged in and authenticated, you are able to begin gathering data from Spotify!

Check out Some Data on 21 Savage

Gather data such as recently played songs on an account, information on specific songs, or information or specific albums! Below we are going to be looking at data of 21 Savage. We can create a table with the following function:

savage%>% 
  select(album_name,track_name, danceability) %>% 
  filter(album_name == "i am > i was") %>% 
  head(15)
##      album_name             track_name danceability
## 1  i am > i was                  a lot        0.837
## 2  i am > i was           break da law        0.904
## 3  i am > i was                    a&t        0.924
## 4  i am > i was      out for the night        0.841
## 5  i am > i was              gun smoke        0.809
## 6  i am > i was                    1.5        0.885
## 7  i am > i was         all my friends        0.713
## 8  i am > i was can't leave without it        0.872
## 9  i am > i was                   asmr        0.840
## 10 i am > i was           ball w/o you        0.892
## 11 i am > i was               good day        0.966
## 12 i am > i was               pad lock        0.959
## 13 i am > i was                monster        0.890
## 14 i am > i was      letter 2 my momma        0.864
## 15 i am > i was                     4L        0.879

As we can see from this function, “good day” has the highest danceability in the album and conversely, “all my friends” has the lowest danceability in the album!

You can also Create Graphs

Graphs can be created using the data collected through the Spotify API. Below we will be looking at a comparison of the danceability levels of 21 Savage throughout his albums. The following function would retrieve a graph comparing the danceability levels:

savage %>% 
  group_by(album_name) %>% 
  select(danceability, track_name) %>% 
  filter(album_name=='i am > i was') %>% 
  ggplot(aes(track_name,danceability))+
  geom_point()

Conclusion

Spotify API can provide key insights to not only artists and there work, but also to personal accounts within the system, trends those accounts follow, and much more in order to benefit the user!