Script to refresh token

What is the problem you are having with rclone?

Token was expired every hour

What is your rclone version (output from rclone version)

rclone v1.51.0

  • os/arch: android/arm64
  • go version: go1.13.7

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

Android 9

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)

rclone about GoogleDrive:

A log from the command with the -vv flag (eg output from rclone -vv copy /tmp remote:tmp)

There is a step by step to update the token using the rclone config, Is it possible to create a .sh file that does this automatically without me having to type anything?

$ rclone config
Current remotes:

Name Type
==== ====
GoogleDrive drive

e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q> e
Choose a number from below, or type in an existing value
1 > GoogleDrive
remote> 1

[GoogleDrive]
type = drive
client_id = 990329642480-fl392inhs4ckln2r62c38ajc3ltkofqd.apps.googleusercontent.com
client_secret = XXX
scope = drive
token = {"access_token":"ya29.XXX","token_type":"Bearer","expiry":"2020-02-22T12:44:07.648805211Z"}
root_folder_id = 0AKXXX

Edit remote
** See help for drive backend at: https://rclone.org/drive/ **

Value "client_id" = "9903XXX"
Edit? (y/n)>
y) Yes
n) No (default)
y/n> n
Value "client_secret" = "XXX"
Edit? (y/n)>
y) Yes
n) No (default)
y/n> n
Value "scope" = "drive"
Edit? (y/n)>
y) Yes
n) No (default)
y/n> n
Value "root_folder_id" = "XXX"
Edit? (y/n)>
y) Yes
n) No (default)
y/n> n
Value "service_account_file" = ""
Edit? (y/n)>
y) Yes
n) No (default)
y/n> n
Edit advanced config? (y/n)
y) Yes
n) No (default)
y/n> n

[GoogleDrive]
type = drive
client_id = 99032XXX
client_secret = XXX
scope = drive
token = {"access_token":"ya29XXX","token_type":"Bearer","expiry":"2020-02-22T12:44:07.648805211Z"}
root_folder_id = 0AKTXXX

y) Yes this is OK (default)
e) Edit this remote
d) Delete this remote
y/e/d> y
Remote config
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> y
    If your browser doesn't open automatically go to the following link: http://127.0.0.1:53682/auth?state=-Vy28o4jkykxxP8GU1vuFg
    Log in and authorize rclone for access
    Waiting for code...
    Got code
    Configure this as a team drive?
    y) Yes
    n) No (default)
    y/n> n
    Current remotes:

Name Type
==== ====
GoogleDrive drive

e) Edit existing remote
n) New remote
d) Delete remote
r) Rename remote
c) Copy remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q> q

rclone automatically handles the refresh of the token just by using it. Are you seeing something else or trying to do something else?

1 Like

After one hour when I try to use the command, I receive this answer.

$ rclone about GoogleDrive:
2020/02/22 15:53:01 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: oauth2: token expired and refresh token is not set

Then I should to do a token refresh showed at first post to that command rclone about works again.

When you authorize and look at your rclone.conf, are you not seeing something like this for the token section?

token = {"access_token":"ya29.blah","token_type":"Bearer","refresh_token":"1/blah-m0FhG5VInVU","expiry":"2020-02-22T14:00:24.947875203-05:00"}
1 Like

I authorized it right now and the file looks like this:

token = {"access_token":"ya29.blah-vv25fkNkjFHF9wNdkhsFp-blah-blah","token_type":"Bearer","expiry":"2020-02-22T20:24:31.921854795Z"}

And what does your about run like now?

felix@gemini:~$ rclone about GD: -vv
2020/02/22 14:39:41 DEBUG : rclone: Version "v1.51.0" starting with parameters ["rclone" "about" "GD:" "-vv"]
2020/02/22 14:39:41 DEBUG : Using config file from "/opt/rclone/rclone.conf"
Used:    107.768T
Trashed: 0
Other:   159.438M
2020/02/22 14:39:41 DEBUG : 5 go routines active

with -vv

I got this:

$ rclone about GoogleDrive: -vv
2020/02/22 20:07:05 DEBUG : rclone: Version "v1.51.0" starting with parameters ["rclone" "about" "GoogleDrive:" "-vv"]
2020/02/22 20:07:05 DEBUG : Using config file from "/data/data/com.termux/files/home/.config/rclone/rclone.conf"
Total: 15G
Used: 10.617G
Free: 93.749M
Trashed: 0
Other: 4.292G
2020/02/22 20:07:07 DEBUG : 5 go routines active
2020/02/22 20:07:07 DEBUG : rclone: Version "v1.51.0" finishing with parameters ["rclone" "about" "GoogleDrive:" "-vv"]
$

The problem definitely relates back to your config and the authorization not dropping in the refresh token, but I'm unsure why offhand.

I deleted my config on my machine and did a GSuite and a regular Google Drive and both populate with a refresh token in there like:

[Test]
type = drive
scope = drive
token = {"access_token":"ya29.Il-blah-blah-blah","token_type":"Bearer","refresh_token":"1//05OsizNvVCQo2CgYIARAAGAUSNwF-blah-tGeM","expiry":"2020-02-22T16:14:57.483514-05:00"}
root_folder_id = blah

What's the OS you are using?

1 Like

Yes, I'm guess too... I'm using Android 9, in my smartphone.

I suspect there is something wrong with your client_id/client_secret. I have a vague memory of this happening before. Try with blank client_id and client_secret to use rclone's and see if that works?

1 Like

I did what you said and it looks like it worked, impressive! I was already giving up, it has been working for over an hour, which did not happen before. I will do new tests in the next few days and let you know. Thank you!

1 Like

Wonder if a time difference is killing it. You can get bad times from cell towers and that can impact your token.

It's really works, thank you so much!

1 Like

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