玩转Google Drive – 资源转存之Rclone使用教程 可直接用folder id,而不用管快捷方式

281次阅读

共计 5470 个字符,预计需要花费 14 分钟才能阅读完成。

Rate this post

记录一下使用过程。

请确保你命令行能顺利 fq:命令行如何 fq

Update 2020.4.23 Google Drive 现引入了快捷方式的文件管理方式,针对这种文件管理方式,我们可以使用 folder id 直接进行资源的拷贝而不用去像之前一样先将资源手动添加到我的网盘!

Update 2019.5.30 一些其他玩法(这是倒序,欢迎交流)

1. 如果要配置 300 个账号怎么弄呢?为了方便,可以在 Windows 主机上用下面的脚本进行配置,后面配置文件 rclone.conf 复制到别的地方也可以用。

for /L %%G in (1,1,300) do rclone config create c%%G drive --drive-client-id "xxx.apps.googleusercontent.com" --drive-client-secret "yyy" --drive-team-drive zzz

配置文件的位置可以输入命令 rclone config file 获得

2. 手上有 rclone.conf 文件,想从普通盘换到团队盘:直接修改 rclone 的配置文件,给对应的盘加上 team_drive = YourTeamdriveID。同理换成别的团队盘直接修改 YourTeamdriveID 即可。

3. 为了更快完成任务,想将官方的 client id 换成自己的:直接在配置文件加 client_id = YourClientIDclient_secret = YourClientSecret 两行。但是 token 还需再登陆认证来刷新一下 …

Rclone 安装和配置记录如下:

Rclone 版本更新较快,以下步骤大致一样,但细节可能稍有不同。若有疑问欢迎留言!

Step 1. 安装 Rclone

Linux 环境

curl https://rclone.org/install.sh | sudo bash

Windows 环境
直接去 Rclone 官网下载 Rclone,然后最好将 rclone.exe 所在目录 加入系统环境变量

Step 2. 参照官方安装指南,配置 Rclone

Rclone 交互式配置
1. 在 Linux 终端或者 Windows CMD/Windows PowerShell 中,输入 rclone config

若在在 Windows 下,请切换到 rclone.exe 所在目录或者将 rclone.exe添加到系统的环境变量中,否则会报“rclone 不是内部或外部命令,也不是可运行的程序或批处理文件”的错误!
2018/12/25 17:19:22 NOTICE: Config file “/root/.config/rclone/rclone.conf” not found – using defaults
No remotes found – make a new one
n) New remote
s) Set configuration password
q) Quit config
e/n/d/r/c/s/q>

2. 输入 n,并给新的远程配置起一个名字

e/n/d/r/c/s/q>n
name> cody_gd1
Type of storage to configure.
Enter a string value. Press Enter for the default (“”).
Choose a number from below, or type in your own value
1 / A stackable unification remote, which can appear to merge the contents of several remotes
“union”
2 / Alias for a existing remote
“alias”
3 / Amazon Drive
“amazon cloud drive”
4 / Amazon S3 Compliant Storage Provider (AWS, Alibaba, Ceph, Digital Ocean, Dreamhost, IBM COS, Minio, etc)
“s3”
5 / Backblaze B2
“b2”
6 / Box
“box”
7 / Cache a remote
“cache”
8 / Dropbox
“dropbox”
9 / Encrypt/Decrypt a remote
“crypt”
10 / FTP Connection
“ftp”
11 / Google Cloud Storage (this is not Google Drive)
“google cloud storage”
12 / Google Drive
“drive”
13 / Hubic
“hubic”
14 / JottaCloud
“jottacloud”
15 / Local Disk
“local”
16 / Mega
“mega”
17 / Microsoft Azure Blob Storage
“azureblob”
18 / Microsoft OneDrive
“onedrive”
19 / OpenDrive
“opendrive”
20 / Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)
“swift”
21 / Pcloud
“pcloud”
22 / QingCloud Object Storage
“qingstor”
23 / SSH/SFTP Connection
“sftp”
24 / Webdav
“webdav”
25 / Yandex Disk
“yandex”
26 / http Connection
“http”
Storage>

3. 选择 Google Drive,这里是输入数字 12(别的版本的 rclone 中 Google Drive 可能对应不同的数字)

Storage> 12
See help for drive backend at: https://rclone.org/drive/

Google Application Client Id
Leave blank normally.
Enter a string value. Press Enter for the default (“”).

4. 用 rclone 的 client_id,直接 回车

client_id> 回车
Google Application Client Secret
Setting your own is recommended.
Enter a string value. Press Enter for the default (“”).

5. 用 rclone 的 client_secret,直接 回车+1

client_secret> 回车
Scope that rclone should use when requesting access from drive.
Enter a string value. Press Enter for the default (“”).
Choose a number from below, or type in your own value
1 / Full access all files, excluding Application Data Folder.
“drive”
2 / Read-only access to file metadata and file contents.
“drive.readonly”
/ Access to files created by rclone only.
3 | These are visible in the drive website.
| File authorization is revoked when the user deauthorizes the app.
“drive.file”
/ Allows read and write access to the Application Data folder.
4 | This is not visible in the drive website.
“drive.appfolder”
/ Allows read-only access to file metadata but
5 | does not allow any access to read or download file content.
“drive.metadata.readonly”
scope>

6. 直接 回车+2

scope> 回车
ID of the root folder
Leave blank normally.
Fill in to access “Computers” folders. (see docs).
Enter a string value. Press Enter for the default (“”).
root_folder_id>

7. 直接 回车+3

root_folder_id> 回车
Service Account Credentials JSON file path
Leave blank normally.
Needed only if you want use SA instead of interactive login.
Enter a string value. Press Enter for the default (“”).
service_account_file>

8. 直接 回车+4

root_folder_id> 回车
Service Account Credentials JSON file path
Leave blank normally.
Needed only if you want use SA instead of interactive login.
Enter a string value. Press Enter for the default (“”).
service_account_file>
Edit advanced config? (y/n)
y) Yes
n) No
y/n>

9. 不编辑高级设置,输入 n

y/n> n
Remote config
Use auto config?
* Say Y if not sure
* Say N if you are working on a remote or headless machine
y) Yes
n) No
y/n>

10. 输入 n(如果是本地安装了浏览器的电脑可以输入y

y/n> n
If your browser doesn’t open automatically go to the following link: https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=202264815744.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=a5409d63a4b6d0063b3e1bf1336261eb
Log in and authorize rclone for access
Enter verification code>
如果出现 connection 相关错误,请确认终端 / 命令行是否翻墙:命令行如何翻墙

11. 复制上链接到浏览器,获得如下形式的 verification code(如果上面步骤 10 选了y,会自动打开浏览器,根据提示登陆账号验证即可)

Enter verification code> 4/fAFDoVQlYzfEsHo0jjWSxXiINSID21yKS3M51hNFeNuH2gyc7t1ebR4
Configure this as a team drive?
y) Yes
n) No
y/n>

12. 输入n(如果是团队盘输入y)

y/n> n
——————–
[cody_gd1] type = drive
token = {“access_token”:”ya29.Gls7B3xW0QneoaH-BKfvbsIJCe7IQuR9Qxq3IHisgSmRfNLhB1o52O2SuY31Lu2VCjr5mX5FIz0cklE5iG16sybT0uY5PPYGI6n6YjZ5xSCGfgV85aSMi8M0aRlk”,”token_type”:”Bearer”,”refresh_token”:”1/ck-ig6X4lf7ql3eX0bqH3ZB0HHpGAccRdGUpf4rV80Y”,”expiry”:”2019-07-05T02:24:16.733118566+08:00″}
——————–
y) Yes this is OK
e) Edit this remote
d) Delete this remote
y/e/d>

13. 输入y

y/e/d> y
Current remotes:

Name Type
==== ====
cody_gd1 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>

14. 输入q

e/n/d/r/c/s/q> q

15. 再检查配置
输入rclone lsd cody_gd1:

root@vultr:~# rclone lsd cody_gd1:
-1 2018-09-13 20:18:10 -1 Colab Notebooks
-1 2017-12-25 20:05:27 -1 Google Photos
-1 2018-02-16 14:27:57 -1 IFTTT
-1 2018-02-05 01:00:06 -1 Music
-1 2018-11-13 11:15:12 -1 周杰伦全集
-1 2018-10-16 15:03:37 -1 王菲合集

可以看到,成功读取 Google Drive 根目录,配置成功

正文完
 
Copyright Puock
 Theme by Puock