Google Drive Drive Does Not Refresh Tokens

What is the problem you are having with rclone?

I run rclone as a scheduled task and essenitally every time I check it (irregularly) it needs to be authorized again. I see various discussions indicating these tokens are refreshed every time the driver is used and expire 7 days after the driver is last used, which is not the observed behavior; this task runs every 15 minutes which gives it 672 opportunities to refresh before that happens and there only possible way for this to occur is if it is failing literally hundreds of times in a row.

You will see from my config that this token expired in mid-April.

Run the command 'rclone version' and share the full output of the command.

.\Documents\rclone-v1.58.0-windows-amd64\rclone.exe version
rclone v1.58.0
- os/version: Microsoft Windows 10 Pro 21H2 (64 bit)
- os/kernel: 10.0.19044.1645 (x86_64)
- os/type: windows
- os/arch: amd64
- go/version: go1.17.8
- go/linking: dynamic
- go/tags: cmount

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)

.\Documents\rclone-v1.58.0-windows-amd64\rclone.exe ls GoogleDrive:

The rclone config contents with secrets removed.

[Dropbox]
type = dropbox
token = {"access_token":"foo","token_type":"bearer","expiry":"0001-01-01T00:00:00Z"}

[GoogleDrive]
type = drive
client_id = bar.apps.googleusercontent.com
client_secret = baz
scope = drive
token = {"access_token":"qux","token_type":"Bearer","refresh_token":"quux","expiry":"2022-04-11T21:01:30.2141687-05:00"}
team_drive = 

[Mega]
type = mega
user = quuz@gmail.com
pass = corge

A log from the command with the -vv flag

.\Documents\rclone-v1.58.0-windows-amd64\rclone.exe -vv ls GoogleDrive:
2022/04/20 20:48:01 DEBUG : rclone: Version "v1.58.0" starting with parameters ["C:\\Users\\qskwood\\Documents\\rclone-v1.58.0-windows-amd64\\rclone.exe" "-vv" "ls" "GoogleDrive:"]
2022/04/20 20:48:01 DEBUG : Creating backend with remote "GoogleDrive:"
2022/04/20 20:48:01 DEBUG : Using config file from "C:\\Users\\qskwood\\.config\\rclone\\rclone.conf"
2022/04/20 20:48:01 DEBUG : GoogleDrive: Loaded invalid token from config file - ignoring
2022/04/20 20:48:01 DEBUG : GoogleDrive: 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."
}
2022/04/20 20:48:02 DEBUG : GoogleDrive: Loaded invalid token from config file - ignoring
2022/04/20 20:48:02 DEBUG : GoogleDrive: 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."
}
2022/04/20 20:48:03 DEBUG : GoogleDrive: Loaded invalid token from config file - ignoring
2022/04/20 20:48:03 DEBUG : GoogleDrive: 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."
}
2022/04/20 20:48:04 DEBUG : GoogleDrive: Loaded invalid token from config file - ignoring
2022/04/20 20:48:04 DEBUG : GoogleDrive: 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."
}
2022/04/20 20:48:05 DEBUG : GoogleDrive: Loaded invalid token from config file - ignoring
2022/04/20 20:48:05 DEBUG : GoogleDrive: 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."
}
2022/04/20 20:48:06 Failed to create file system for "GoogleDrive:": 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 GoogleDrive:": oauth2: cannot fetch token: 400 Bad Request
Response: {
  "error": "invalid_grant",
  "error_description": "Token has been expired or revoked."
}

Bonus

.\Documents\rclone-v1.58.0-windows-amd64\rclone.exe -vv config reconnect GoogleDrive:
2022/04/20 20:54:58 DEBUG : rclone: Version "v1.58.0" starting with parameters ["C:\\Users\\qskwood\\Documents\\rclone-v1.58.0-windows-amd64\\rclone.exe" "-vv" "config" "reconnect" "GoogleDrive:"]
2022/04/20 20:54:58 DEBUG : Using config file from "C:\\Users\\qskwood\\.config\\rclone\\rclone.conf"
2022/04/20 20:54:58 DEBUG : GoogleDrive: config in: state="", result=""
2022/04/20 20:54:58 DEBUG : GoogleDrive: config out: out=&{State:*oauth,teamdrive,, Option:<nil> OAuth:<nil> Error: Result:}, err=<nil>
2022/04/20 20:54:58 DEBUG : GoogleDrive: config in: state="*oauth,teamdrive,,", result=""
2022/04/20 20:54:58 DEBUG : GoogleDrive: config out: out=&{State:*oauth-confirm,teamdrive,, Option:true OAuth:<nil> Error: Result:}, err=<nil>
2022/04/20 20:54:58 DEBUG : GoogleDrive: config: reading config parameter "config_refresh_token"
Already have a token - refresh?
y) Yes (default)
n) No
y/n> y
2022/04/20 20:55:01 DEBUG : GoogleDrive: config in: state="*oauth-confirm,teamdrive,,", result="true"
2022/04/20 20:55:01 DEBUG : GoogleDrive: config out: out=&{State:*oauth-islocal,teamdrive,, Option:true OAuth:<nil> Error: Result:}, err=<nil>
2022/04/20 20:55:01 DEBUG : GoogleDrive: config: reading config parameter "config_is_local"
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> y
2022/04/20 20:55:11 DEBUG : GoogleDrive: config in: state="*oauth-islocal,teamdrive,,", result="true"
2022/04/20 20:55:11 DEBUG : GoogleDrive: config out: out=&{State:*oauth-do,teamdrive,, Option:<nil> OAuth:<nil> Error: Result:}, err=<nil>
2022/04/20 20:55:11 DEBUG : GoogleDrive: config in: state="*oauth-do,teamdrive,,", result=""
2022/04/20 20:55:11 NOTICE: Make sure your Redirect URL is set to "http://127.0.0.1:53682/" in your custom config.
2022/04/20 20:55:11 DEBUG : Starting auth server on 127.0.0.1:53682
2022/04/20 20:55:12 NOTICE: If your browser doesn't open automatically go to the following link: http://127.0.0.1:53682/auth?state=SPYO9-VKWob-FocUyL1T5Q
2022/04/20 20:55:12 NOTICE: Log in and authorize rclone for access
2022/04/20 20:55:12 NOTICE: Waiting for code...
2022/04/20 20:55:12 DEBUG : Redirecting browser to: https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=bar.apps.googleusercontent.com&redirect_uri=http%3A%2F%2F127.0.0.1%3A53682%2F&response_type=code&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive&state=grault
2022/04/20 20:55:19 DEBUG : Received GET request on auth server to "/"
2022/04/20 20:55:19 NOTICE: Got code
2022/04/20 20:55:19 DEBUG : Closing auth server
2022/04/20 20:55:19 DEBUG : Closed auth server with error: accept tcp 127.0.0.1:53682: use of closed network connection
2022/04/20 20:55:19 DEBUG : Saving config "token" in section "GoogleDrive" of the config file
2022/04/20 20:55:19 DEBUG : Keeping previous permissions for config file: -rw-rw-rw-
2022/04/20 20:55:19 DEBUG : GoogleDrive: Saved new token in config file
2022/04/20 20:55:19 DEBUG : GoogleDrive: config out: out=&{State:*oauth-done,teamdrive,, Option:<nil> OAuth:<nil> Error: Result:}, err=<nil>
2022/04/20 20:55:19 DEBUG : GoogleDrive: config in: state="*oauth-done,teamdrive,,", result=""
2022/04/20 20:55:19 DEBUG : GoogleDrive: config out: out=&{State:teamdrive Option:<nil> OAuth:<nil> Error: Result:}, err=<nil>
2022/04/20 20:55:19 DEBUG : GoogleDrive: config in: state="teamdrive", result=""
2022/04/20 20:55:19 DEBUG : GoogleDrive: config out: out=&{State:teamdrive_ok Option:false OAuth:<nil> Error: Result:}, err=<nil>
2022/04/20 20:55:19 DEBUG : GoogleDrive: config: reading config parameter "config_change_team_drive"
Configure this as a Shared Drive (Team Drive)?

y) Yes
n) No (default)
y/n> n
2022/04/20 20:55:24 DEBUG : GoogleDrive: config in: state="teamdrive_ok", result="false"
2022/04/20 20:55:24 DEBUG : Saving config "team_drive" in section "GoogleDrive" of the config file
2022/04/20 20:55:24 DEBUG : Keeping previous permissions for config file: -rw-rw-rw-
2022/04/20 20:55:24 DEBUG : GoogleDrive: config out: out=<nil>, err=<nil>
2022/04/20 20:55:24 DEBUG : rclone: Version "v1.58.0" finishing with parameters ["C:\\Users\\qskwood\\Documents\\rclone-v1.58.0-windows-amd64\\rclone.exe" "-vv" "config" "reconnect" "GoogleDrive:"]

The token now expires in one hour. I will post the results of attempting to refresh the token at that time.

I just ran rclone.exe ls GoogleDrive: and it worked. My config file indicates the token did get refreshed.

I'm not sure when it's failing, but it never does it in the short term. It's always when I check a few days or weeks later than I find it hasn't been working.

hi,

fwiw, whenever i run rclone, always use a debug log flie.
after rclone has completed, run a script that checks the exit code, scans the log for errors and other specifc info.

I'm having what sounds like the identical problem. I thought it was needing to "publish" my app, but apparently not.

I've run out of ideas for help since there is no support with Google unless you pay for it. This is just for my personal use for backing up one directory on my home PC, I don't have a company that would pay for me to get support on this. Going to keep an eye out to see if you find a solution.

one option is to use a service account file, which does not use a tokens, thus does not expire.

The scheduled task indicates success.

I enabled task history in Windows's Task Scheduler.

This is what I'm seeing since 8:30 AM yesterday (over 24 hours, over 100 attempts):

This scheduled task is configured to terminate if it executes for longer than 10 minutes. The rclone process is not currently running. Why does Windows think it is already running?

as i suggested above, need to use rclone debug log.

What additional information do you think a debug log is going to produce?

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