Help Wizard

Step 1

NEXT STEP

Invalid refresh token

Solved!

Invalid refresh token

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']

 

 

 

Reply

Accepted Solutions
Marked as 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"
    }

View solution in original post

3 Replies

I recommend you to look again at "Request a refreshed Access Token".

I did exactly the same thing, the problem remained.

Marked as 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"
    }

Suggested posts