前言

此篇文章只是针对 Google Drive 网盘直链分享、在线观影、加密保护 这篇文章解决某些问题

问题

在那篇文章中,挂载成功之后,会发生网盘内容为空的事件,虽然 F5 刷新即可,但是这样体验很不好

原因也很简单,这是因为用的 rclone 的公共 api ,一旦 api 超限,所以就会导致内容空的事情发生

解决也非常简单,用自己的 client_idclient_secretrefresh_token

前提

你需要创建一个项目,地址:https://console.cloud.google.com

img

然后再创建 OAuth 同意屏幕,这个很简单,自己看着步骤填写即可,注意选择外部,反正那时候我是选择外部的

img

正式开始

创建项目和配置 OAuth 同意屏幕之后了,我们去开启 Google Drive API

地址:开启 Google Drive API

接着创建一个 OAuth client ID,地址:Create OAuth

应用类型选择桌面应用

img

创建成功之后,吧 client_idclient_secret 复制下来,一会要用到

安装 Rclone

我选择的是 Windows 版本

下载到本地之后,解压缩,然后在坏境变量 Path 添加 Rclone 的路径

img

接着继续再添加一个 http_proxy,因为 cmd 它默认不走代理啊,所以只能这样了,或者你可以在 cmd 中执行 set http_proxy=http://ip:代理端口,这个算是临时代理吧,cmd 窗口一关闭就失效了

img

获取 refresh_token

直接执行 rclone config 即可

1
2
3
4
5
6
7
$ rclone config

No remotes found - make a new one
n) New remote
s) Set configuration password
q) Quit config
n/s/q> n

输入 n,新建一个

1
2
3
4
5
6
7
8
9
10
11
12
13
name> goindex		# 名字随便取
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 / 1Fichier
\ "fichier"
2 / Alias for an existing remote
\ "alias"
... 此处忽略 3-12
13 / Google Drive
\ "drive"
...
Storage> 13

我们选择 13,Google Drive

1
2
3
4
5
6
7
8
9
10
Google Application Client Id
Setting your own is recommended.
See https://rclone.org/drive/#making-your-own-client-id for how to create your own.
If you leave this blank, it will use an internal key which is low performance.
Enter a string value. Press Enter for the default ("").
client_id> ******************* # 你的 client_id
Google Application Client Secret
Setting your own is recommended.
Enter a string value. Press Enter for the default ("").
client_secret> ******************* # 你的 client_secret

输入刚刚创建 OAuth client ID 成功之后的 client_idclient_secret

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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> 1

此处我们选择 1,表示所有权限

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
ID of the root folder
Leave blank normally.

Fill in to access "Computers" folders (see docs), or for rclone to use
a non root folder as its starting point.

Note that if this is blank, the first time rclone runs it will fill it
in with the ID of the root folder.

Enter a string value. Press Enter for the default ("").
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 (default)
y/n> n

输入 n

1
2
3
4
5
6
7
Remote config
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

输入 n

1
2
3
Please go to the following link: https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=8888888888888-p888888888888888091.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=0NMrhpEREX28r25plm3ZwA
Log in and authorize rclone for access
Enter verification code> *****************************************************************

然后就会给你个地址,复制并在浏览器打开,然后授权,你会得到一串授权码,并吧授权码粘贴到命令行中,回车

1
2
3
4
Configure this as a team drive?
y) Yes
n) No (default)
y/n> n

n 代表不是团队盘,也就是个人云端硬盘,如果你是团队盘的话,那就 y

然后就会得到一串 json

1
{"access_token":"*************************************************","token_type":"******","refresh_token":"1//0eMnSsUDUyIB****************************************************************************","expiry":"2021-**********************"}

其他的都没用,只要 refresh_token

完成了以上所有配置,那么我相信你已经有了 client_idclient_secretrefresh_token

接着我们打开 CloudFlare Worker

把这仨换成自己的

img

大功告成!