Skip to content

Instantly share code, notes, and snippets.

@jlitven
Last active November 6, 2016 16:38
Show Gist options
  • Save jlitven/922583d192f0b981ae8c40b94c1f7725 to your computer and use it in GitHub Desktop.
Save jlitven/922583d192f0b981ae8c40b94c1f7725 to your computer and use it in GitHub Desktop.
library(httr) # for sending requests
# Get the Spotify token header for API calls
# Returns:
# Header for GET requests
get_token_header = function(){
clientID = 'your client id here'
secret = 'your secret id here'
response = POST(
'https://accounts.spotify.com/api/token',
accept_json(),
authenticate(clientID, secret),
body = list(grant_type = 'client_credentials'),
encode = 'form',
verbose()
)
mytoken = content(response)$access_token
HeaderValue = paste0('Bearer ', mytoken)
return(HeaderValue)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment