Getting "invalid_grant" error with google oauth the second time

I am using google oAuth for my python application in which I have the function of automatically logging into Google using Google. When I try to log in for the first time, it will be successful, but the next time if I log in, it will fail, and every time I get 500 internal server errors.

When I checked the error logs, I received the following error message on the line "credentials = oAuthFlow.step2_exchange (code)"

Failed to retrieve access token: { "error" : "invalid_grant" } 

I have a valid clientId registered with Google. Can anyone tell me why this is happening. I am using python 2.7.

+4
source share
1 answer

This can be caused by any number of things, including ...

  • User revoked permission
  • Scopes changed
  • Google deleted your update token
  • Errors in your code that represent the wrong update token. Remember that you will ONLY receive the update token for the first time. On subsequent calls, the update token will be empty, because you must save it in your database.

I get this a lot when I use the same user for testing and live use, as two update tokens tend to rewrite each other.

The good news is that regardless of the reason, the decision is always the same. You need to force re-authorization from the user.

+6
source

Source: https://habr.com/ru/post/1499779/


All Articles