Type in your question below and we'll check to see what answers we can find...
Loading article...
Submitting...
If you couldn't find any answers in the previous step then we need to post your question in the community and wait for someone to respond. You'll be notified when that happens.
Simply add some detail to your question and refine the title if needed, choose the relevant category, then post.
Before we can post your question we need you to quickly make an account (or sign in if you already have one).
Don't worry - it's quick and painless! Just click below, and once you're logged in we'll bring you right back here and post your question. We'll remember what you've already typed in so you won't have to do it again.
Plan
Premium
Country
UA
Device
PC
Operating System
Windows 11
My Question or Issue
Hello, trying to do an automatic access token refresh, but for some reason when I do, the query returns an error to me: {"error": "invalid_grant", "error_description": "Invalid refresh token"}
My refresh token is 100% correct.
Here is my code to get the access token:
data = {
'grant_type': 'refresh_token',
'refresh_token': refresh_token,
'client_id': client_id,
}
headers = {
'Authorization': 'Basic ' + base64.urlsafe_b64encode(f'{client_id}:{client_secret}'.encode('ascii')).decode(),
'Content-Type': 'application/x-www-form-urlencoded'
}
response = requests.post(token_url, data=data, headers=headers)
if response.status_code == 200:
oauth_token = response.json()['access_token']
Solved! Go to Solution.
My solution is:
encoded = base64.b64encode((client_id + ":" + client_secret).encode("ascii")).decode("ascii")
data = {
"grant_type": "client_credentials"
}
auth_headers = {
"Authorization": "Basic " + encoded,
"Content-Type": "application/x-www-form-urlencoded"
}
I recommend you to look again at "Request a refreshed Access Token".
I did exactly the same thing, the problem remained.
My solution is:
encoded = base64.b64encode((client_id + ":" + client_secret).encode("ascii")).decode("ascii")
data = {
"grant_type": "client_credentials"
}
auth_headers = {
"Authorization": "Basic " + encoded,
"Content-Type": "application/x-www-form-urlencoded"
}
Hey there you, ย Yeah, you!ย 😁 ย Welcome - we're glad you joined the Spotify Community! ย While you here, let's have a fun game and getโฆ