This method was updated at July 12, 2017. But I think that this is a temporal workaround. When the official update is done for retrieving revision files, this will be updated.
In order to use this, at first, please retrieve your access token and enable Drive API.
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
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
Retrieve a file from revision id.
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.
curl -sSLG \
-H 'Authorization: Bearer ### Access token ###' \
"https://www.googleapis.com/drive/v2/files/### FileID ###/revisions?fields=items(exportLinks%2Cid)"
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.
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.
curl -sSLG \
-H 'Authorization: Bearer ### Access token ###' \
"https://www.googleapis.com/drive/v3/files/### FileID ###/revisions/### RevisionID ###?alt=media" \
-o outputfilename
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
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."
}
}
This method was also used for ggsrun.