Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading