Google Drive cannot refresh token after a few days

I tried with the latest master version and with the 1.54.0.beta.5077.14c0d8a93 provided by Ubuntu. I'll try with the latest stable version.

Here is the output of rclone config reconnect PersonalGDrive: -vv

2021/02/02 09:18:20 DEBUG : rclone: Version "v1.54.0-DEV" starting with parameters ["rclone" "config" "reconnect" "PersonalGDrive:" "-vv"]
2021/02/02 09:18:20 DEBUG : Using config file from "/home/laloge_h/.config/rclone/rclone.conf"
Already have a token - refresh?
y) Yes (default)
n) No
y/n> y
Use auto config?
 * Say Y if not sure
 * Say N if you are working on a remote or headless machine
y) Yes (default)
n) No
y/n> n
Please go to the following link: https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=foobar1234.apps.googleusercontent.com&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&state=abcdef
Log in and authorize rclone for access
Enter verification code> 4/56789abcdef-g
2021/02/02 09:18:45 DEBUG : PersonalGDrive: Saved new token in config file
Configure this as a team drive?
y) Yes
n) No (default)
y/n> n
2021/02/02 09:18:48 DEBUG : rclone: Version "v1.54.0-DEV" finishing with parameters ["rclone" "config" "reconnect" "PersonalGDrive:" "-vv"]
1 Like

same problem with fedora 33 fully updated and rclone installed from official fedora repos:

dnf search rclone -v
Loaded plugins: builddep, changelog, config-manager, copr, debug, debuginfo-install, download, generate_completion_cache, needs-restarting, playground, repoclosure, repodiff, repograph, repomanage, reposync, system-upgrade
DNF version: 4.5.2
cachedir: /var/cache/dnf
Last metadata expiration check: 0:28:16 ago on Wed 03 Feb 2021 02:04:29 AM CET.
======================================================= Name Exactly Matched: rclone =======================================================
rclone.x86_64 : Rsync for cloud storage
Repo        : @System
Matched from:
Provide    : rclone = 1.53.3-1.fc33

..

rpm -qa | grep rclone
rclone-1.53.3-1.fc33.x86_64

..

rclone -vvv version                            
2021/02/03 02:36:22 DEBUG : rclone: Version "v1.53.3-DEV" starting with parameters ["rclone" "-vvv" "version"]
rclone v1.53.3-DEV
- os/arch: linux/amd64
- go version: go1.15.5
2021/02/03 02:36:22 DEBUG : rclone: Version "v1.53.3-DEV" finishing with parameters ["rclone" "-vvv" "version"]

..

rclone about gdrive: --config rclone.conf -vvv
2021/02/03 02:37:36 DEBUG : rclone: Version "v1.53.3-DEV" starting with parameters ["rclone" "about" "gdrive:" "--config" "rclone.conf" "-vvv"]
Enter configuration password:
password:
2021/02/03 02:37:43 DEBUG : Using config file from "redacted/rclone.conf"
2021/02/03 02:37:43 DEBUG : Creating backend with remote "gdrive:"
2021/02/03 02:37:43 DEBUG : gdrive: Loaded invalid token from config file - ignoring
2021/02/03 02:37:43 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/02/03 02:37:44 DEBUG : gdrive: Loaded invalid token from config file - ignoring
2021/02/03 02:37:44 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/02/03 02:37:45 DEBUG : gdrive: Loaded invalid token from config file - ignoring
2021/02/03 02:37:45 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/02/03 02:37:46 DEBUG : gdrive: Loaded invalid token from config file - ignoring
2021/02/03 02:37:46 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/02/03 02:37:47 DEBUG : gdrive: Loaded invalid token from config file - ignoring
2021/02/03 02:37:47 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/02/03 02:37:48 DEBUG : 4 go routines active
2021/02/03 02:37:48 Failed to about: About call failed: failed to get Drive storageQuota: Get "https://www.googleapis.com/drive/v3/about?alt=json&fields=storageQuota&prettyPrint=false": 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."
}

..

[gdrive]
type = drive
client_id = redacted
client_secret = redacted
scope = drive
token = redacted
root_folder_id = redacted

on two pc (laptop and desktop) this works for few days than stops, first post here please excuse me if i missed infos or else :wink:

perhaps, it does on not matter but the only thing i see in common is using versions that do not look like they are from rclone.org.

  • v1.54.0-DEV
  • 1.53.3-1.fc33
  • v1.53.3-DEV

perhaps get an official version from https://rclone.org/downloads/
v1.54.0

thanks, usually packages from big distros official repos as fedora (or ubuntu as per Hugal31) are trustworthy but i will follow your advice and install official rclone rpm from download link. i will report back, it will take some times to se if this happends again (i mainly use rclone for some personal project few times a week, does this matter at all?)

Are you running rclone simultaneously? So more than one rclone running at once? I'm just wondering if this is a problem with the config file getting overwritten.

Are you running rclone simultaneously?

I'm almost sure no. I have multiple scripts running with run-parts using cron, so my rclone invocations are not parallel.

Besides, even if they do overwrite the configuration, the refresh token is not renewed between calls. Worst case scenario, a valid access_token is overwritten with another valid access_token.

I'm not sure what is going on here! Whether the problem is with your installation or whether it is with your Google account...

It might be worth going to your drive settings and disconnecting rclone

Then doing rclone config reconnect nameofyourremote: to make rclone work again.

If that doesn't work then if you can run all your rclone commands with -vv to a log file and look for

2021/02/03 13:05:38 DEBUG : drive: Saved new token in config file

That is when rclone has successfully renewed the token.

I guess the other thing to check would be is the time correct on your computer? Oauth relies on the time being spot on.

1 Like

no, i work on laptop few days, rclone sync local to gdrive then move to desktop rclone symc gdrive to local and so on.. <50mb sync.. really light usage..

on other note i already disconnected and reconnected rclone from google account to test previously and as far as i know i have 0 problems with time sync (i also have other apps that are time sensitive).

this was just to give some feedback. thanks.

Ok well if it goes wrong again, let me know! And if you work out why, even better :slight_smile:

same problem here running on rpi4 ubuntu 20.04
rclone v1.54.0

  • os/arch: linux/arm64
  • go version: go1.15.7

it happens after about a week. then I just renew the token manually using the url -> authorize and it works again..

Are you using your own client_id? To a normal gmail.com account?

1 Like

yes as without it's slower I think?

1 Like

Yes.

I'm just trying to find the common factor...

1 Like

could this be the culprit? i do have my consent screen in testing, maybe other users in this thread can report about this?

sorry for bad link, remove space, new user cannot post links.

edit: just an update my desktop failed to refresh token today after my last message here 4d ago

2021/02/08 08:22:20 DEBUG : 4 go routines active
2021/02/08 08:22:20 Failed to lsd with 2 errors: last error was: couldn't list directory: Get "https://www.googleapis.com/drive/v3/files?alt=json&fields=files%28id%2Cname%2Csize%2Cmd5Checksum%2Ctrashed%2CexplicitlyTrashed%2CmodifiedTime%2CcreatedTime%2CmimeType%2Cparents%2CwebViewLink%2CshortcutDetails%2CexportLinks%29%2CnextPageToken%2CincompleteSearch&includeItemsFromAllDrives=true&pageSize=1000&prettyPrint=false&q=trashed%3Dfalse+and+%28%270AGZ4xiMeA7saUk9PVA%27+in+parents%29&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."
}
1 Like

I also use a custom client_id, created as told in the drive tutorial. I also have the "in-dev app" consent screen.

1 Like

Ah, so this paragraph in particular

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.

We should probably make a note of that in the drive setup.

Which step should it go it?

2 Likes

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.

AH! That's look like an answer. We should indeed update the drive page. Should I mark your answer as the solution?

1 Like

Want to have a go? Click the pencil icon at the top right of this page: https://github.com/rclone/rclone/blob/master/docs/content/drive.md

The relevant section starts at line 1284

2 Likes

Might be a good idea!

1 Like

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