gdown/命令行下载Google Drive文件(大文件也可以)

中小型文件 - 使用gdown

安装gdown

pip install gdown

获取Google drive文件(不能是文件夹)的ID
在这里插入图片描述
复制到的链接大概长下面这个样子,其中加粗的部分就是文件的ID
https://drive.google.com/file/d/12LhpGHvGu4wIgXrONspNKqfGFpTfr0-p/view?usp=drive_link

在Python中运行(注意下面的url和上面的不太一样)

>>> import gdown
>>> url = 'https://drive.google.com/uc?id=12LhpGHvGu4wIgXrONspNKqfGFpTfr0-p'
>>> output = 'file_name.txt'
>>> gdown.download(url, output, quiet=False)

这个方法对中小型文件可行,但对过大的文件(以上图中40GB的文件为例,文件ID1CDuzEbjK1hPbMItoJwrLIMgK25FSRM6_),会报下面的错

Access denied with the following error:

        Too many users have viewed or downloaded this file recently. Please
        try accessing the file again later. If the file you are trying to
        access is particularly large or is shared with many people, it may
        take up to 24 hours to be able to view or download the file. If you
        still can't access a file after 24 hours, contact your domain
        administrator.

You may still be able to access the file from the browser:

         https://drive.google.com/uc?id=1CDuzEbjK1hPbMItoJwrLIMgK25FSRM6_

这时,就需要使用Token和命令行下载(以下内容参考自stackoverflow)。

大型文件 - 命令行

  • 进入 https://developers.google.com/oauthplayground/

  • 找到这一条并点击,然后点下面的 Authorize APIs
    在这里插入图片描述

  • 再点击出现的Exchange authorization code for tokens

  • 复制生成的 Access Toekn

  • 在终端运行(注意,下面的ACCESS_TOKEN要换成刚才复制的,FILE_ID改成要下载的文件IDFILE_NAME改成要保存的文件名)

curl -H "Authorization: Bearer ACCESS_TOKEN" https://www.googleapis.com/drive/v3/files/FILE_ID?alt=media -o FILE_NAME

然后就开始漫长的传输了。
在这里插入图片描述

  • 10
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

负反馈循环

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值