BAIS 462 Assignment 5

Author

Olivia Delffs

Explanation of Spotify API

Spotify is a free music streaming service that also acts as an extensive data base. This data contains loads of information regarding songs, albums, artists, playlists, users, number of streams, etc. To avoid working with all of this data in a singular set, the API allows you to choose only the information you would like to analyze.

API Setup

To work with this tool, you first want to install and load “spotifyr”, which is the package that handles Spotify’s API.

library(spotifyr)
Warning: package 'spotifyr' was built under R version 4.2.3

To gain access, visit this webpage: developer.spotify.com/documentation/web-api. Then click the dashboard link, log in with your Spotify credentials, click the “Create App” button, and follow the sign-up instructions. Then, click on your profile to get your client_id and client_secret values.

To set your authentication, fill your client_id and client_secret in the code below.

Sys.setenv(client_id ="your client id")
Sys.setenv(client_secret = "your client secret")
accessToken <- get_spotify_access_token()

To find an artists top tracks, go to Spotify’s website. Search for the artist that you would like to use, and using the share artist link, select the string between the ‘/’ after artist, and the question mark. For example, the share link for SZA is https://open.spotify.com/artist/7tYKF4w9nC0nq9CsPZTHyP?si=4fBxSDDPSdyXPAbZTcJgeg, and her artist ID is ‘7tYKF4w9nC0nq9CsPZTHyP’. When you use the get_artist_top_tracks function, it provides many variables describing the top songs, so to only see the names of the tracks, install and load the ‘tidyverse’ package. Then, put the artist ID in the function, and use the pipe operator to select only the variable that contains the name of each song.

library(tidyverse)
get_artist_top_tracks('7tYKF4w9nC0nq9CsPZTHyP') %>% select(name)
                                      name
1                                Kill Bill
2                                   Snooze
3                Slime You Out (feat. SZA)
4         TELEKINESIS (feat. SZA & Future)
5  Rich Baby Daddy (feat. Sexyy Red & SZA)
6                 Kiss Me More (feat. SZA)
7                 All The Stars (with SZA)
8                                Good Days
9           Open Arms (feat. Travis Scott)
10                                     Low