Home > front end >  How to fix Google API 'invalid_grant' error
How to fix Google API 'invalid_grant' error

Time:03-01

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.

CodePudding user response:

if you check the documentation for expiration you will find the cause of your issue.

A Google Cloud Platform project with an OAuth consent screen configured for an external user type and a publishing status of "Testing" is issued a refresh token expiring in 7 days.

Set your app to production in Google developer console and your refresh tokens will last longer then seven days.

  • Related