How to set revision history with Google Apps Scrip

2020-07-10 09:35发布

问题:

Trying to figure out something with the Advanced Google Apps Services and Google Apps Scripts. I want to essentially alter documents to revert them back to a prior revision but doing it programmatically instead of using Google drives UI. I have pieced together code to get me the revisionID through some searching and perusing Google Apps Scripts data on the Drive API, I had thought I found what I needed to update the sheet accordingly. However, I am stuck. I do not fully understand how Update is used. Drive.Revisions.Update(), I had thought that if you passed parameters it is looking for I would be able to set a Google spreadsheet back to the revision I specified.

function listRevisions(fileId) {
  var fileId = '1yck2UQDJztdqD3Ji8UT3KcwTKiA0bgLd2-4xqwbU824';
  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(revision.id);
    }
  } else {
   Logger.log('No revisions found.');
  }
}

function alterRevision(){
  var fileId = '1yck2UQDJztdqD3Ji8UT3KcwTKiA0bgLd2-4xqwbU824';
  var change = Drive.Revisions.get(fileId, 1306);
  var update = Drive.Revisions.update(change, fileId, 1306);
  Logger.log(update.id + update.modifiedDate);
} 

Pretty basic, I use listRevisions on a specific sheet to get the revisionID. I had planned to use alterRevision to reset the test sheet back to a prior listed revision.

Perhaps I am not understanding how the drive API works. I was hoping to get some clarity as to why this is not updating the sheet to the revision I am passing to the update() call.

Apologies if the format is wrong the question is not worded right.

EDIT

alterRevisions console output

[16-10-05 15:14:51:798 CDT] 1306 2016-05-02T16:20:57.841Z

It actually grabs the correct date of the revision I want to make as the actual file. I just don't think update is what I thought it would be. Or perhaps there is another step to make it the live revision effectively performing the restore of an older revision function. I also tried adding other properties of my update variable just to see other bits of data if possible.

Execution logs were rather uninformative to me.

[16-10-05 15:30:37:970 CDT] Starting execution
[16-10-05 15:30:39:732 CDT] Logger.log([1306 2016-05-02T16:20:57.841Z undefined true, []]) [0 seconds]
[16-10-05 15:30:39:733 CDT] Execution succeeded [1.757 seconds total runtime]