问题
I wanna make a very simple bash script for downloading files from google drive via Drive API
, so in this case there is a big file on google drive and I installed OAuth 2.0 Playground
on my google drive account, then in the Select the Scope
box, I choose Drive API v3
, and https://www.googleapis.com/auth/drive.readonly
to make a token and link.
After clicking Authorize APIs
and then Exchange authorization code for tokens
. I copied the Access token
like below.
#! /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"
but it won't work, any idea ?
for example the size of my file is 12G, when I run the code I will get this as output and after a second it back to prompt again ! I checked it in two computers with two different ip addresses.(I also add alt=media
to URL)
-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#
the content of file that it created is like this
{
"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."
}
}
回答1:
- You want to download a file from Google Drive using the curl command with the access token.
If my understanding is correct, how about this modification?
Modified curl command:
Please add the query parameter of alt=media
.
curl -H "Authorization: Bearer $token" "https://www.googleapis.com/drive/v3/files/$id?alt=media" -o "$file"
Note:
- This modified curl command supposes that your access token can be used for downloading the file.
- In this modification, the files except for Google Docs can be downloaded. If you want to download the Google Docs, please use the Files: export method of Drive API. Ref
Reference:
- Download files
If I misunderstood your question and this was not the direction you want, I apologize.
回答2:
This is a known bug
It has been reported in this Issue Tracker post. This is caused because as you can read in the documentation:
(about download url)
Short lived download URL for the file. This field is only populated for files with content stored in Google Drive; it is not populated for Google Docs or shortcut files.
So you should use another field.
You can follow the report by clicking on the star next to the issue number to give more priority to the bug and to receive updates.
As you can read in the comments of the report, the current workaround is:
- Use webContentlink instead
or
- Change
www.googleapis.com
tocontent.googleapis.com
来源:https://stackoverflow.com/questions/60608901/how-to-download-a-big-file-from-google-drive-via-curl-in-bash