I am correctly scoping for offline access and am storing that. Every 60 minutes, when needed, I retrieve a new access_token. Code has not changed, but what is odd is that when he first went through the authorization.
client_id ="xxxxx.apps.googleusercontent.com"
client_secret ="xxxxxxxxxxxxxxxxxxxx"
refresh_token ="xxxxxxxxxxxxxxxxxxx"
response = oauth2a.RefreshToken(client_id,client_secret,refresh_token)
def RefreshToken(client_id, client_secret, refresh_token):
params = {}
params['client_id'] = client_id
params['client_secret'] = client_secret
params['refresh_token'] = refresh_token
params['grant_type'] = 'refresh_token'
request_url = AccountsUrl('o/oauth2/token')
response = urllib.urlopen(request_url, urllib.urlencode(params)).read()
return json.loads(response)
The response is always:
{u'error': u'invalid_grant'}.
I have attempted this on three different machines, and I also get
HTTPError: HTTP Error 400: Bad Request
Go to https://developers.google.com/oauthplayground. Make sure you added this URL to your Authorized redirect URIs in the previous step. In the top right corner, click the settings icon, check "Use your own OAuth credentials" and paste your Client ID and Client Secret.
Invalid_grant error has two common causes.
invalid_grant
error response is returned. The limit for each unique pair of OAuth 2.0 client and is 25 refresh tokens (note that this limit is subject to change). If the application continues to request refresh tokens for the same Client/Account pair, once the 26th token is issued, the 1st refresh token that was previously issued will become invalid. The 27th requested refresh token would invalidate the 2nd previously issued token and so on.I've had the same issue(windows OS). and I've fixed that by just updating the time server synchronization and it works now perfectly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With