Assignment 5

Author

Lindsey Utterback

Introduction

The service I intend to demonstrate is my Spotify data such as who my top artists are, what songs I listen to, or learn various information about some of the artist’s songs I listen to. In a company this could be used for creating customizable playlists for targeting a group of people or featuring popular artist as sponsors for your product based on your target groups playlists. I chose this because Spotify is my preferred application to listen to music on.

R

Below are some libraries that must be loaded into your script for the Spotify API to function properly

# library(spotifyr)
# library(tidyverse)
# library(httpuv)
# library(knitr)
# library(lubridate)

Setting up Spotify API

  1. Log in to Spotify API dashboard using your Spotify account at https://developer.spotify.com/documentation/web-api
  2. In top right corner select dashboard from the click-down arrow
  3. Click create app:
  4. Enter the name of your app (ex: “Spotify_462”)
  5. Enter an app description to explain what you are using the app for (ex: “School”)
  6. Enter the website of your company (ex: https://www.xavier.edu/)
  7. Enter a redirect URI which is the location where the authorization server sends the user after the app is authorized
  8. Do not check anything in the box that asks you select web api or sdk
  9. Next you must agree to the terms and services of Spotify’s “Developer” by checking the box
  10. Click save

R, Spotify Authorization

To use this API you must use this code using your client ID and client secret that is given to you through your app and run this code to authorize the app. Once authorized you can use the API to explore Spotify data.

# Sys.setenv(SPOTIFY_CLIENT_ID = 'XXXX')
# Sys.setenv(SPOTIFY_CLIENT_SECRET = 'XXXX')


# access_token <- get_spotify_authorization_code(scopes = scopes()[c(7,8,14,15)])

# auth <- get_spotify_authorization_code(  client_id = Sys.getenv("SPOTIFY_CLIENT_ID"),client_secret = Sys.getenv ("SPOTIFY_CLIENT_SECRET"),scope = scopes()[c(7,8,14,15)])

# access_token <- auth

R, API Features:

In this code I first demonstrate how to create a vector for Selena Gomez songs by calling the API for any songs she is in. Next I create a csv file of her songs and the information of her songs that Spotify has. After that I decided to call the API to retrieve information of the top five keys that are used in her songs.

# Call to action for Selena Gomez's audio features
# Selena <- 
  # get_artist_audio_features('Selena Gomez')

# reading the csv 
# Selena_Gomez <- read_csv("Selena.csv")

# Selena Gomez's top five keys

# Selena_Gomez %>% 
    # count(key_mode, sort = TRUE) %>% 
    # head(5) %>% 
    # kable()