9

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"
}

3 Answers 3

5

This is because your authorization token has expired.

Currently there is an open Issue to improve this error message here.

You should delete your token with rm ~/.gdrive/token_v*.json then run the gdrive about command to reauthorize

4

Managed to resolve this by retriggering gcloud authorization with:

gcloud auth application-default login
2

The steps I fixed it:

  1. rm ~/.gdrive/token_v2.json as other answer suggested.

  2. But I get danger error if I open the link get from gdrive about to re-authorize: enter image description here

  3. So I create a drive project by go to https://developers.google.com/drive/api/v3/quickstart/js and click "Enable the Drive API":

    enter image description here

  4. Click the "API Console" link on that dialog:

    enter image description here

  5. 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:

    enter image description here

  6. Ensure select "Other" type:

    enter image description here

  7. 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"
    
  8. 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: enter image description here

  9. Click "Allow" it, copy/paste the code back to gdrive about and done:

enter image description here

1
  • As of today there is no option to select 'Application type' - Other.| I was not able to do this. It always asks me "Enter verification code:"
    – nitinr708
    Aug 29, 2020 at 11:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.