How can I get the revision history in Google Docs using a script?
How can I do it? Some ideas?
How can I get the revision history in Google Docs using a script?
How can I do it? Some ideas?
It's possible you need to enable the Drive SDK (which you do in the Resources -> Advanced Google Services Menu) and then do something like this
var revisions = Drive.Revisions.list(fileId);
if (revisions.items && revisions.items.length > 0) {
for (var i = 0; i < revisions.items.length; i++) {
var revision = revisions.items[i];
var date = new Date(revision.modifiedDate);
Logger.log('ID: %s, Date: %s, File size (bytes): %s', revision.id, date.toLocaleString(),
revision.fileSize);
}
} else {
Logger.log('No revisions found.');
}
To get the file ID use SpreadsheetApp.getActiveSpreadsheet().getId();
or DocumentApp.getActiveDocument().getId();
I can't believe it, but it seems to be impossible to get a revision-history version of a Google Docs "file" programmatically. I checked the Drive SDK thoroughly and it seems all we can do is download the Google Document in some other format (probably losing details on the conversion). There's no generating a new Google Document from the revision, or even restoring a revision over the current file.
So, you could "download" a specific revision-history as a docx and then re-upload it converting back to Google Docs (ugh!), and then access normally. To do so you'll have to enable the Drive API v2 advanced service (under the Resources menu). And use the Drive SDK reference (linked above) to get the revision history and do this manoeuvre.