gpt4 book ai didi

bash - 如何通过Bash中的curl从谷歌驱动器下载大文件?

转载 作者:行者123 更新时间:2023-12-02 02:39:39 30 4
gpt4 key购买 nike

我想制作一个非常简单的 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."
}
}

最佳答案

  • 您想使用带有访问 token 的 curl 命令从 Google Drive 下载文件。

  • 如果我的理解是正确的,这个修改怎么样?

    修改 curl 命令:

    请添加 alt=media的查询参数.
    curl -H "Authorization: Bearer $token" "https://www.googleapis.com/drive/v3/files/$id?alt=media" -o "$file"

    笔记:
  • 此修改后的 curl 命令假设您的访问 token 可用于下载文件。
  • 在此修改中,可以下载除 Google Docs 之外的文件。如果您想下载 Google Docs,请使用 Drive API 的 Files: export 方法。 Ref

  • 引用:
  • Download files

  • 如果我误解了您的问题并且这不是您想要的方向,我深表歉意。

    关于bash - 如何通过Bash中的curl从谷歌驱动器下载大文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60608901/

    30 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com