This method was updated at July 12, 2017.
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)'
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)'
Reference : https://developers.google.com/drive/v3/reference/revisions/list
3. File for Revision ID
Retrieve a file from revision id.
For Google Docs
For Google Docs (spreadsheet, document, slide and drawing), since recently I noticed that the revision files would not be able to be retrieved using Drive API v3, I modified this using new workaround.
**New workaround : ** The new workaround is to use Drive API v2. drive.revisions.get
of Drive API v2 can retrieve not only the revision list, but also the export links. I thought of the use of the export links. This became the new workaround.
This sample downloads spreadsheet using revision ID.
1. Retrieve Revision List and Export Links
curl -sSLG \
-H 'Authorization: Bearer ### Access token ###' \
"https://www.googleapis.com/drive/v2/files/### FileID ###/revisions?fields=items(exportLinks%2Cid)"
2. Retrieve Revision File from Export Link
curl -sSLG \
-H 'Authorization: Bearer ### Access token ###' \
"https://docs.google.com/spreadsheets/export?id=### FileID ###&revision=### revision number ###&exportFormat=xlsx" \
-o outputfilename.xlsx
I don’t know when this workaround will not be able to be used. But if this could not be used, I would like to investigate of other method.
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.
When the revision list of GAS is retrieved, following error occurs.
{
"error": {
"errors": [
{
"domain": "global",
"reason": "revisionsNotSupported",
"message": "The file does not support revisions."
}
],
"code": 403,
"message": "The file does not support revisions."
}
}