prasmussen / gdrive

Google Drive CLI Client
MIT License
8.99k stars 1.19k forks source link

TUTORIAL: How to get rid of 403 Errors #426

Open TanukiAI opened 5 years ago

TanukiAI commented 5 years ago

How to get rid of 403 errors

Many people get Errors like Failed to get file: googleapi: Error 403: Rate Limit Exceeded, rateLimitExceeded and thanks to LINKIWI https://github.com/prasmussen/gdrive/issues/392#issuecomment-423048518 I found a way to fix it properly.

What causes the problem?

The developer made one API for this program and an Google API can "only" make 10 million requests at a day. That means that too many people use this program and the requests gets full.

How much does an own API cost?

Nothing, Google made them free for everyone.

How do I fix it then?

You have to make an own API, download the programing language go, change the API to your own one and compile it to an .exe. (And btw. binary editing resulted in errors)

And now step by step:

  1. Download "go" for your platform from https://golang.org/dl/ and install it following the instructions for your platform here and download Git from https://git-scm.com/downloads and install it with standard settings

  2. Download the repository as .zip from GitHub and unzip it in a new folder or simply execute git clone https://github.com/gdrive-org/gdrive.git image

  3. Log into your Google Account (or create one) and go to the Google Developer API Website (and if needed accept the ToS)

  4. Click on "Create Project" image

  5. and then click "CREATE" image

  6. Give it a name (in my case "Google CLI TA40") and click "Create" image

  7. Now go to Google Drive API and click "ENABLE" image

  8. Now on the left side, click "Credentials" image

  9. And click "CREATE CREDENTIAL" image

  10. Fill the things like I did and then click on "What credentials do I need?" image

  11. Give it a name (I took the name of the API) image

  12. Next select your e-mail and then give it a name (I again took the name of the API) image

  13. Click on "Download" (A .json file will be downloaded) image

  14. Open the .json file in the editor of your choice.(Notepad++ prefered) You should see :

    • "client_id" which looks like this: 81915486XXXX-XXXX22bh62ql2rbnaqtpds82od4ql976.apps.googleusercontent.com
    • "client_secret" which are random characters like this: lnA7ZFg5NEGOMpFhd6e4Pqny
  15. In the unzipped repository open the file names "handlers_drive.go" (via Notepad++) and change these 2 variables to the ones you got in step 14 image and save it

  16. open CMD/terminal and go to the folder where the "handerls_drive.go" is. First type this: go get github.com/prasmussen/gdrive (thanks to mbenlioglu https://github.com/prasmussen/gdrive/issues/426#issuecomment-459046466) Now type this: go build -ldflags '-w -s' Now you should have an executable for you platform which you can use normally

You can reset your data by deleting the %appdata%\.gdrive on Windows, $HOME/.gdrive on other platforms

Cross Compiling a Linux/OS X/Windows etc. version of gdrive from your device:

If you want to compile the binary for an OS other than the one you're using you should first set GOOS and GOARCH variables for that system. Look up your target OS here: https://golang.org/doc/install/source#environment

Now do this in terminal: On Windows:

SET GOOS=your os
SET GOARCH=your arch

On Mac OS/Linux:

export GOOS=your os
export GOARCH=your arch

then do go build -ldflags '-w -s'

Example variables if target platform is a 64 bit Linux machine: GOOS=linux GOARCH=amd64


Edit: Updated to cover all platforms

mbenlioglu commented 5 years ago

It will possible to put API key in argument, to avoid each people compile his own executable ?

It'll be one of the first issues to be addressed, since it's making the program unstable. I'm currently having tight deadlines, I'll inspect pr's and reorganize repo as soon as I catch a break.

rohfle commented 5 years ago

@ordimans

It will possible to put API key in argument, to avoid each people compile his own executable ?

Not on command line, but as a file on disk, there is currently unmerged pull request - https://github.com/gdrive-org/gdrive/pull/428

The pull request allows you to override credentials with a client_id.json file in the ~/.gdrive directory.

Amendill commented 5 years ago

Try to re-create a new token may be it solve your problem.

If you mean.. remove current token..gDrive give me to get token again by going web URL then.. I have done that few times still same. Let me know if you mean anything else simple tell me the process if you don't mind.

I have same your problem. I've done 2 things below

  1. After I modified handlers_drive.go then I also copy this file into ~/go/src/github.com/prasmussen/gdrive/handlers_drive.go before build package.
  2. I've re-create new token.

After that I open google console to monitor the api request. Good luck.

Thank you it worked for me !

ppbrown commented 5 years ago

I made a patch that allows direct use of the credentials.json file.

476

This is better than the prior pull 428, because "credentials.json" is the exact filename used by google when you generate new creds from a project. So everything becomes dragndrop with no fiddling around. (edit: and. umm.. its a LOT smaller patch ;) )

rohfle commented 5 years ago

I agree with @ppbrown - #476 is way simpler. The only thing better about #428 is that it loads and uses the entire credentials file as exported from Google API console. #476 loads the credentials, extracts the client id and secret, and then recreates the credentials json with constant values for login endpoints, scopes etc that are set inside gdrive.

Do we really care about this? Probably not unless these constant values or the format of the credentials file are changed by Google.

One other thing to note - when I download credentials from Google API Console, I get a randomly named file like client_secret_892342893429834_[...].json.

michaeledi commented 5 years ago

A typo here:

open CMD/terminal and go to the folder where the "handerls_drive.go" is

should be "handlers_drive.go" lol

marufshidiq commented 4 years ago

Hello everyone, i try to create a repository https://github.com/marufshidiq/gdrive-cli-builder to build this application with our Google API credentials and the build process is using GitHub Actions, so we don't need to setup anything in our computer. I have been used this to build my own app, i hope this can help anyone who want to build this app with much easier.

avatar-lavventura commented 3 years ago

@rohfle It still asked me to enter the Enter verification code: , should it still ask it after we made all the changes on the source code and compile it?

tcel2 commented 3 years ago

I wonder if someone could create a fork of this. Then, the OP steps could be made 10 times. Then, the executable would be generated 10 times. Then, if running executable1 fails with 403 error, it would automatically try the executable2 and so on. I think it is not too complicated to implement, just will require some effort to make it 10 times.

And if you are used to code/compile on this language, may be, it does not need to be 10 big executables, but just 10 small libraries that the code would internally switch to let the magic happen! :)

Yes, each one would require each user to allow the permissions, but that is not a big deal at all.

mesutalturk commented 3 years ago

Hello, The application is no longer working for the last 1 month. what has changed? it gives the following error.

Failed getting oauth client: Failed to exchange auth code for token: oauth2: cannot fetch token: 400 Bad Request Response: { "error": "invalid_grant", "error_description": "Bad Request" }

ppbrown commented 3 years ago

possibly google has changed the required syntax on their side

On Tue, Feb 16, 2021 at 3:28 AM mesutalturk notifications@github.com wrote:

Hello, The application is no longer working for the last 1 month. what has changed? it gives the following error.

Failed getting oauth client: Failed to exchange auth code for token: oauth2: cannot fetch token: 400 Bad Request Response: { "error": "invalid_grant", "error_description": "Bad Request" }

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

mesutalturk commented 3 years ago

@ppbrown how do we fix this. developer no longer supports :(

leekung commented 3 years ago

@ppbrown how do we fix this. developer no longer supports :(

I think this #570 fix the 403 issue. I am using it without problem