0
votes

Per the doc, if you want to refresh your access token, you can make an HTTP call to "https://oauth2.googleapis.com/token" with providing client_id, client_secret, grant_type, refresh_token.

Code:

user = User.query.filter_by(email='[email protected]').first()  
with open('client_secret.json') as d:
    d = json.load(d)
thecredentials = { 
    'client_id': d['web']['client_id'],
    'client_secret':d['web']['client_secret'],
    'refresh_token':user.refresh,
    'grant_type': user.refresh,
    'redirect_uri': "http://localhost:5000/",
    'access_type':'offline'
}
req = requests.post(url='https://oauth2.googleapis.com/token', data = thecredentials)
print(req.text)
return str(req)

Despite adding 'redirect_uri' and 'access_type' based on some research, I keep on getting:

{
  "error": "unsupported_grant_type",
  "error_description": "Invalid grant_type: 1//04JBbHWUWxwS3CgYIARAAGAQSNwF-L9IrZyyrHpxIoerJ4XZkAuGosXeeRHiYvdEQG7uF5EO5jWSC_-9mrRMAhmM30JHZvgyIhbM"
}
1
The error description is clear. You are not putting refresh_token as grant_type, but putting the refresh token.Hernán Alarcón
isn't it the same thing? To be honest, I was confused by specifically. Should it be something like this: refresh_token = user.refresh thecredentials = { 'client_id': d['web']['client_id'], 'client_secret':d['web']['client_secret'], 'refresh_token':refresh_token, 'grant_type': refresh_token}Daniyal dehleh
It would be great if you can clarify it by a sample code or something.Daniyal dehleh
In this case, the value of grant_type is required to be refresh_token. So please modify 'grant_type': user.refresh, to 'grant_type': 'refresh_token', and test it again.Tanaike
ohh okk. Thank you so much!!Daniyal dehleh

1 Answers

1
votes

For using refresh tokens the grant type should be: grant_type = refresh_token.

See https://developers.google.com/android-publisher/authorization#using_the_refresh_token