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='daniyaldehleh@gmail.com').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"
}
refresh_token
asgrant_type
, but putting the refresh token. – Hernán Alarcónrefresh_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 dehlehgrant_type
is required to berefresh_token
. So please modify'grant_type': user.refresh,
to'grant_type': 'refresh_token',
and test it again. – Tanaike