Search⌘ K
AI Features

Refresh Access Tokens

Understand how to refresh Spotify API access tokens to maintain seamless authorization. Learn to generate new client credential tokens and refresh authorization code tokens for effective API integration.

Client credential access token

Click the "Run" button to generate a new client credential access token.

Python
URL = "https://accounts.spotify.com/api/token?grant_type=client_credentials"
encoded = base64.b64encode('{{CLIENT_ID}}:{{CLIENT_SECRET}}')
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Basic '+encoded
}
response = requests.request("POST", URL, headers=headers).json()
print(json.dumps(response, indent=4))

Authorization code access token

Use the code below to generate an authorization code access token using a refresh token.

Python
URL = "https://accounts.spotify.com/api/token?grant_type=refresh_token&refresh_token={{REFRESH_TOKEN}}"
encoded = base64.b64encode('{{CLIENT_ID}}:{{CLIENT_SECRET}}')
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Basic '+encoded
}
response = requests.request("POST", URL, headers=headers).json()
print(json.dumps(response, indent=4))