Spotify is it one of the largest music streaming services in the world, rivaling Apple Music, SoundCloud, Tidal and more. With its nearly 500 million users, it keeps of track of individual user statistics and is known for its data usage.
Spotify has a vast API system that authorizes information to be analyzed conveniently. It allows for users to see data on their own personal account, and data on any Spotify interests they may have.
With all the information and data that the API permits, there are numerous insights in which it can be used. Looking at an individual users statistics, users can dive deeper into what music they listen to by genre, artist, time listened, etc. This can tell whether or not someone has a diversified music taste or one-dimensional. In the business aspect, when analyzing popular artist or genres as a whole, marketers can research into how popular they are. For example, if an up and coming artist is gaining attention from sponsors, they can see streaming statistics to determine whether it is worth investing in the artist.
The API requires a few pre requisites such as:
+A Spotify Account
+Account on Spotify Developers Website
+Authentication using credentials from an App Creation
The authentication process consists of a Client ID and a Client Secret ID gained from the App creation. Using this information users will be given an access token that allows for given resources or personal data through the API.
# Comment out code and enter your ID information
# Sys.setenv(SPOTIFY_CLIENT_ID = "XXXXXXXXX")
# Sys.setenv(SPOTIFY_CLIENT_SECRET = ("XXXXXXXXXXXXXXXXX")
# access_token <- get_spotify_access_token()
Spotifyr is an R wrapper that is specific for the Spotify Web Api. It allows for an easier way to access and analyze data.
# install.packages("spotifyr")
# library(spofityr)
With this package there are number of functions you can use to find
more about personal preferences and Spotify. A few functions are:
+get_album(s) : access specific albums from the Spotify catalog, can get
1 or multiple
+get_artist(s) : access specific artists from the Spotify catalog, can
get 1 or multiple
+get_my_playlists : access current users list of playlists
These are just a few functions spotifyr offers. To see the full list of functions it is quite simple. In the view or output in the lower right hand side of the R interface, click “packages”, search for “spotifyr” and a full dictionary will list all the functions.
Here is an example of my last 5 most played artist and their genres on my Spotify account.
get_my_top_artists_or_tracks(type = 'artists', time_range = 'long_term', limit = 5) %>%
select(name, genres) %>%
knitr::kable()
| name | genres |
|---|---|
| Lil Baby | atl hip hop, atl trap , rap , trap |
| A Tribe Called Quest | alternative hip hop, conscious hip hop , east coast hip hop , gangster rap , golden age hip hop , hardcore hip hop , hip hop , jazz rap , queens hip hop , rap |
| Kendrick Lamar | conscious hip hop, hip hop , rap , west coast rap |
| A$AP Rocky | east coast hip hop, hip hop , rap , trap |
| Future | atl hip hop , rap , southern hip hop, trap |
Yes, I like rap…