我想制作一个非常简单的 bash 脚本,用于通过 Drive API
从谷歌驱动器下载文件,所以在这种情况下,谷歌驱动器上有一个大文件,我安装了 OAuth 2.0 Playground
在我的谷歌驱动器帐户上,然后在 Select the Scope
盒子,我选择Drive API v3
, 和 https://www.googleapis.com/auth/drive.readonly
制作 token 和链接。
点击后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."
}
}
最佳答案
如果我的理解是正确的,这个修改怎么样?
修改 curl 命令:
请添加
alt=media
的查询参数.curl -H "Authorization: Bearer $token" "https://www.googleapis.com/drive/v3/files/$id?alt=media" -o "$file"
笔记:
引用:
如果我误解了您的问题并且这不是您想要的方向,我深表歉意。
关于bash - 如何通过Bash中的curl从谷歌驱动器下载大文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60608901/