【发布时间】:2020-06-21 20:03:23
【问题描述】:
我想制作一个非常简单的 bash 脚本,用于通过 Drive API 从谷歌驱动器下载文件,所以在这种情况下,谷歌驱动器上有一个大文件,我在我的谷歌驱动器帐户上安装了 OAuth 2.0 Playground,然后在 @ 987654324@框,我选择Drive API v3和https://www.googleapis.com/auth/drive.readonly做token和link。
点击Authorize APIs,然后点击Exchange authorization code for tokens。我复制了Access token,如下所示。
#! /bin/bash
read -p 'Enter your id : ' id
read -p 'Enter your new token : ' token
read -p 'Enter your file name : ' file
curl -H "Authorization: Bearer $token" "https://www.googleapis.com/drive/v3/files/$id?alt=media" -o "$file"
但它不起作用,你知道吗?
例如,我的文件大小是 12G,当我运行代码时,我会得到它作为输出,一秒钟后它会再次提示!我在两台具有两个不同 ip 地址的计算机上检查了它。(我还在 URL 中添加了alt=media)
-bash-3.2# bash mycode.sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 166 100 166 0 0 80 0 0:00:02 0:00:02 --:--:-- 80
-bash-3.2#
它创建的文件内容是这样的
{
"error": {
"errors": [
{
"domain": "global",
"reason": "downloadQuotaExceeded",
"message": "The download quota for this file has been exceeded."
}
],
"code": 403,
"message": "The download quota for this file has been exceeded."
}
}
【问题讨论】:
-
超出了问题的范围,但如果它有用 - 我发现使用 rclone在 CLI 上将内容移入/移出 Google Drive 非常容易
标签: bash curl oauth-2.0 google-drive-api