Timofey Melentev
Timofey Melentev

Reputation: 91

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:

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

Upvotes: 0

Views: 2597

Answers (3)

Ronnie Smith
Ronnie Smith

Reputation: 18565

The following command will fix it.

gcloud auth application-default login

Upvotes: 0

Luciano
Luciano

Reputation: 1168

Another potential problem: Missing or expired default credentials.

Some apps depend on Google Cloud default credentials to operate. These are sometimes read off of environment variables from the executing shell. Note that these can still cause problems even if you use gcloud auth login to log in to non-default credentials.

Check that your default credential token is valid by running the following:

gcloud auth application-default print-access-token

See this article for more details.

Upvotes: 2

Linda Lawton - DaImTo
Linda Lawton - DaImTo

Reputation: 116948

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.

Upvotes: 1

Related Questions