I introduce 2 kinds of methods. One is to use curl
. Another is to use wget
. At this time, I could know that wget
can be also used as same as curl
.
In order to use this, at first, please retrieve your access token and enable Drive API.
1. File ID
Retrieve file id from file name.
curl -X GET -sSL \
-H 'Authorization: Bearer ### Access token ###' \
'https://www.googleapis.com/drive/v3/files?q=name="### FileName ###"&fields=files(id,name)'
wget -q --header='Authorization: Bearer ### Access token ###' \
'https://www.googleapis.com/drive/v3/files?q=name="### FileName ###"&fields=files(id,name)' \
Reference : https://developers.google.com/drive/v3/reference/files/list
2. Revision ID
Retrieve revision id from file id.
curl -X GET -sSL \
-H 'Authorization: Bearer ### Access token ###' \
'https://www.googleapis.com/drive/v3/files/### FileID ###/revisions?fields=revisions(id%2CmodifiedTime)'
wget -q --header='Authorization: Bearer ### Access token ###' \
'https://www.googleapis.com/drive/v3/files/### FileID ###/revisions?fields=revisions(id%2CmodifiedTime)' \
-O out.txt
Reference : https://developers.google.com/drive/v3/reference/revisions/list
3. File for Revision ID
Retrieve a file from revision id.
For Google Docs
This sample downloads spreadsheet using revision ID. For URL query, both revisions=### RevisionID ###
and revision=### RevisionID ###
can be used.
curl -sSLG \
-d "mimeType=application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" \
-H 'Authorization: Bearer ### Access token ###' \
"https://www.googleapis.com/drive/v3/files/### FileID ###/export?revisions=### RevisionID ###" \
-o outputfilename.xlsx
wget -q --header='Authorization: Bearer ### Access token ###' \
"https://www.googleapis.com/drive/v3/files/### FileID ###/export?revisions=### RevisionID ###&mimeType=application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" \
-O outputfilename.xlsx
This method hasn’t been shown in Google, as you say. Although I don’t know why, I investigated how to download revision files by trial and error. Finally, I could find it. As a result, the method was very simple. But I spent to find this for a lot of time.
Except for Google Docs
In the case of except for Google Docs, the revision ID is just file ID. So you can download not only using revision ID, but also as a normal file.
Pattern 1
curl -sSLG \
-H 'Authorization: Bearer ### Access token ###' \
"https://www.googleapis.com/drive/v3/files/### FileID ###/revisions/### RevisionID ###?alt=media" \
-o outputfilename
Pattern 2
curl -sSLG \
-H 'Authorization: Bearer ### Access token ###' \
"https://www.googleapis.com/drive/v3/files/### RevisionID ###?alt=media" \
-o outputfilename
Reference : https://developers.google.com/drive/v3/reference/revisions/get
For GAS
At current stage, the revisions of project (GAS) cannot be retrieved yet. Because there are a revision history for each project at the script editor, there are possibly some methods for retrieving them using APIs. But I don’t know yet. I’m sorry.