Skip to content

Instantly share code, notes, and snippets.

@jlitven
Last active November 6, 2016 16:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jlitven/90b14faf11d29a0709d02453960c3394 to your computer and use it in GitHub Desktop.
Save jlitven/90b14faf11d29a0709d02453960c3394 to your computer and use it in GitHub Desktop.
library(jsonlite) # for parsing JSON
# Get a playlist list
# Arguments:
# user_id - string
# playlist_id - string
# Returns:
# list of playlist info
get_playlist = function(user_id, playlist_id){
# Request playlist
URI = paste0('https://api.spotify.com/v1/users/', user_id,'/playlists/', playlist_id)
request = GET(url = URI, add_headers(Authorization = HeaderValue))
playlist_info = fromJSON(content(request, "text"))
return(playlist_info)
}
# Get tracks of a playlist
# Arguments:
# playlist_id - string
# user_id - string
# Returns:
# Data frame of tracks
get_tracks = function(playlist_id, user_id){
# Request tracks
URI = paste0('https://api.spotify.com/v1/users/', user_id,'/playlists/', playlist_id,'/tracks')
response2 = GET(url = URI, add_headers(Authorization = HeaderValue))
tracks = fromJSON(content(response2, "text"))$items$track
return(tracks)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment