Rclone connecting to Google Drive "bad token"

What is the problem you are having with rclone?

Rclone simply stopped working. The desktop showed a gdrive (connected to Google Drive) disk icon but I was unable to see any directory contents either in the console nor in the GUI. This was working fine this morning but by this afternoon it was not. After a reboot it appeared to have sorted itself out but when I tried to access the Google Drive directory from the Pi I got nowhere. I made a fresh back-up of the SD card this morning before doing anything. After encountering this issue I restored the backup image I had made but still no joy.

I even set up a new gdrive in rclone with new credentials etc and still get the same result.

What is your rclone version (output from rclone version)

rclone v1.55.1

Which OS you are using and how many bits (eg Windows 7, 64 bit)

Linux raspberrypi 5.10.17+ #1421 Thu May 27 13:58:02 BST 2021 armv6l GNU/Linux

Which cloud storage system are you using? (eg Google Drive)

Google Drive

The command you were trying to run (eg rclone copy /tmp remote:tmp)

During the new set-up I got to the mount testing and hit the problem here:

 rclone ls --max-depth 1 gdrive:

The rclone config contents with secrets removed.

[gdrive]
type = drive
client_id = xx
client_secret = xx
scope = drive
token = xx

[d]
type = drive
client_id = xx
client_secret = xx
scope = drive
token =  xx

A log from the command with the -vv flag

I hope I understood the instructions correctly here.

pi@raspberrypi:~ $ rclone ls -vv --max-depth 1 gdrive:
2021/07/09 23:39:50 DEBUG : Using config file from "/home/pi/.config/rclone/rclone.conf"
2021/07/09 23:39:50 DEBUG : rclone: Version "v1.55.1" starting with parameters ["rclone" "ls" "-vv" "--max-depth" "1" "gdrive:"]
2021/07/09 23:39:50 DEBUG : Creating backend with remote "gdrive:"
2021/07/09 23:39:50 DEBUG : gdrive: Loaded invalid token from config file - ignoring
2021/07/09 23:39:52 DEBUG : gdrive: Token refresh failed try 1/5: oauth2: cannot fetch token: 400 Bad Request
Response: {
  "error": "invalid_grant",
  "error_description": "Token has been expired or revoked."
}
2021/07/09 23:39:53 DEBUG : gdrive: Loaded invalid token from config file - ignoring
2021/07/09 23:39:53 DEBUG : gdrive: Token refresh failed try 2/5: oauth2: cannot fetch token: 400 Bad Request
Response: {
  "error": "invalid_grant",
  "error_description": "Token has been expired or revoked."
}
2021/07/09 23:39:54 DEBUG : gdrive: Loaded invalid token from config file - ignoring
2021/07/09 23:39:54 DEBUG : gdrive: Token refresh failed try 3/5: oauth2: cannot fetch token: 400 Bad Request
Response: {
  "error": "invalid_grant",
  "error_description": "Token has been expired or revoked."
}
2021/07/09 23:39:55 DEBUG : gdrive: Loaded invalid token from config file - ignoring
2021/07/09 23:39:55 DEBUG : gdrive: Token refresh failed try 4/5: oauth2: cannot fetch token: 400 Bad Request
Response: {
  "error": "invalid_grant",
  "error_description": "Token has been expired or revoked."
}
2021/07/09 23:39:56 DEBUG : gdrive: Loaded invalid token from config file - ignoring
2021/07/09 23:39:56 DEBUG : gdrive: Token refresh failed try 5/5: oauth2: cannot fetch token: 400 Bad Request
Response: {
  "error": "invalid_grant",
  "error_description": "Token has been expired or revoked."
}
2021/07/09 23:39:57 Failed to create file system for "gdrive:": couldn't find root directory ID: Get "https://www.googleapis.com/drive/v3/files/root?alt=json&fields=id&prettyPrint=false&supportsAllDrives=true": couldn't fetch token - maybe it has expired? - refresh with "rclone config reconnect gdrive:": oauth2: cannot fetch token: 400 Bad Request
Response: {
  "error": "invalid_grant",
  "error_description": "Token has been expired or revoked."

NB -- This is all with a brand new set of credentials, tokens, etc. I even got e-mail from Google asking if I had given access to Google Drive to rclone and I confirmed it.

Thank you for any help!

Seems like your client ID/secret might be removed or you need to reconnect:

https://rclone.org/commands/rclone_config_reconnect/

Is it a personal Google Drive or GSuite?

First off, it's just a personal drive not GSuite.

After looking at the link about 'reconnect' I ended up just re-making my Rclone-GoogeDrive connection with a few hiccoughs along the way, but I seem to have gotten it working again. I think I may have missed a set-up detail. Getting all that set up in Google Developer Console is a bit Byzantine. I also suspect that the interface has changed a bit since the directions I followed were posted.

Just one question remains in my mind; Why didn't it work when I booted up from the backup which was working fine at backup time?

Thanks for your input!

If you are using a personal account, how did you make the client ID/secret? If you don't push the publish button to make it production, a set of client ID/secret will only last a week in the test mode and need to be recreated.

This is interesting and puzzling at the same time. I have the RPi set up to run a cron job once every 24hrs. It reads a shared Google Drive folder and its subfolders to generate a simply formatted plain text file table of contents of that shared folder.

This has run for weeks, even a few months on end without fail. The RPi has even re-booted itself at least once via watchdog and then continued on with its once-a-day chore. So the expiration after a week in 'testing' mode is confusing me. I had a look on the OAuth consent screen and did not see mention of an expiration after a week. There is a notice about a user cap:


While publishing status is set to "Testing", only test users are able to access the app. Allowed user cap prior to app verification is 100, and is counted over the entire lifetime of the app. Learn more


"Learn more" at the end there is a link. There was nothing there about a week long limit under testing mode. Under "Test users" I'm the only one listed. If there is a seven day limit on client ID/secret how did it work for weeks on end? Could it be that once connected and running non-stop it could continue after a one-week period? Then what about its continued operation following the watchdog re-boot?

Pushing the 'publish' button triggers other requirements which I can't meet as far as I know.

Are you using a personal Google Account or a GSuite account?

I don't know anything about GSuite so I'm assuming it's just a personal Google Account as I mentioned earlier.

You need to hit publish on that screen if you want to have it last.

image

Don't worry about anything it asks as it will publish.

OK. This is where I am now:

Verification Status

Needs verification

Because you're using one or more sensitive scopes, your app registration requires verification by Google. Please prepare your app to submit for verification. [ Learn more ]

There is a "Prepare for Verification" button below that.

You can also just leave it as a test and add a test user instead if you rather do that:

image

Well, I already listed myself as a test user so I should be good to go.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.