This post is a followup to How to make \'access_type=offline\' / server-only OAuth2 operations on GAE/Python. The http = credentials.authorize(httplib2.Http())
An invalid_grant
is returned when the refresh token can't be used to get a new access token from the current user. This is happening to you because the stored Credentials
object has a null refresh token, i.e.
>>> credentials.refresh_token is None
True
As mentioned in the NOTE in How to make 'access_type=offline' / server-only OAuth2 operations on GAE/Python?:
If a user has already authorized your client ID, the subsequent times you perform OAuth for these users they will not see the OAuth dialog and you won't be given a refresh token.
You need to make sure your Credentials
are stored with a valid refresh token and the easiest way to do this, as mentioned in your last question as well as in all 3 questions you linked to is to use approval_prompt=force
when creating your OAuth2WebServerFlow
or OAuth2Decorator
object (whichever you are using).