Reputation: 675
Suddenly, gdrive
command line tool stops working, and always gives the following error message:
Failed to get about: Get https://www.googleapis.com/drive/v3/about?alt=json&fields=maxImportSizes%2CmaxUploadSize%2CstorageQuota%2Cuser: oauth2: cannot fetch token: 400 Bad Request
Response: {
"error": "invalid_grant",
"error_description": "Bad Request"
}
Upvotes: 16
Views: 20223
Reputation: 5361
Managed to resolve this by retriggering gcloud
authorization with:
gcloud auth application-default login
Upvotes: 13
Reputation: 7803
The steps I fixed it:
rm ~/.gdrive/token_v2.json
as other answer suggested.
But I get danger error if I open the link get from gdrive about
to re-authorize:
So I create a drive project by go to https://developers.google.com/drive/api/v3/quickstart/js and click "Enable the Drive API":
Click the "API Console" link on that dialog:
To make default redirect url (i.e. urn:ietf:wg:oauth:2.0:oob
) works, we need Installed type app and can't use "Web application type app"(which only allow http/https scheme). So click "Create credentials" and choose "Oauth client ID" item:
Ensure select "Other" type:
Copy "Client ID" and "Client secret" from created item. cd
to ~/.go/src/github.com/prasmussen/gdrive/
, then replace both at this two variables in handlers_drive.go
file, save it, e.g.:
const ClientId = "xxx.apps.googleusercontent.com"
const ClientSecret = "xxx"
Then run go install
at that directory. Now run gdrive about
and open that link in web browser. I get This app isn't verified
error page. You are the author who created that app on above steps and suppose safe. Nevertheless simply click "Advanced" link and click Go to Quickstart (unsafe)
link:
Click "Allow" it, copy/paste the code back to gdrive about
and done:
Upvotes: 2