Last active
November 6, 2016 16:49
-
-
Save jlitven/90b14faf11d29a0709d02453960c3394 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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