'How to fix Google API 'invalid_grant' error

I am using Google API with Drive API and Drive Activity API to handle and make changes to files. Everything seems to work fine, but at random day of the week I receive an invalid_grant error. I have read about timezone solutions and other 8-9 issues, but I think this is something else.

This is how I work with API:

  • Get credentials from DB -> use them to auth.
  • Getting new access_token and refresh_token every time my application executes the auth function, setting tokens to credentials and updating it in DB.
  • Every time user wants to do anything with drive or receiving new changes via google webhook, auth method is being triggered (if authClient static field which is storing OAuth2Client is undefined)

So it works fine, but this invalid_grant error ruins everything. I have no idea what to do with this.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source