2016-02-29 125 views
3

我想知道如何使用高级云端硬盘服务以编程方式恢复为固定版本的文件。通过高级云端硬盘服务还原Google文档

我在这里看到的文档
https://developers.google.com/apps-script/advanced/drive#listing_revisions这里
https://developers.google.com/drive/v3/reference/#Revisions

我已经试过

var revs = Drive.Revisions.list(fileId); 
var revArr = revs.items; 
var len = revArr.length; 
var rev = revArr[len - 2]; 
var rev2 = revArr[len - 1]; 
var revId = rev.id; 
var revId2 = rev2.id; 
// These will throw an id mismatch error. 
Drive.Revisions.update(rev, fileId, revId2); 
Drive.Revisions.patch(rev, fileId, revId2); 
// These don't seem to revert the file. 
Drive.Revisions.update(rev2, fileId, revId2); 
Drive.Revisions.patch(rev2, fileId, revId2); 

我只想把该文件,并使其恢复的修订版。 我不想下载旧文件,但需要将当前文件恢复到之前的状态。例如:
例如。 FileA rev0 -> {Edited: Change Text to gibberish} -> FileA rev1
(使用ADS)Drive.Revisions.revertTo(rev0.id); //Or something like that.

我已经尝试了一堆不同的东西,但似乎无法得到它的工作。

+0

没有任何直接的方法可以做到这一点,但是每个修订版本都会保存在Google云端硬盘中,就像单独的文件一样。您可以直接获取修订版或发布要使用的修订版。您可以在[文档](https://developers.google.com/drive/v3/web/manage-revisions#tips_and_tricks)中观看视频以获取更多信息。 – gerardnimo

回答

0

你可以尝试获取的docx导出链接,看看有多少是恢复修订:

var response = UrlFetchApp.fetch(
    "https://docs.google.com/feeds/download/documents/export/Export?id=<FILEID>&revision=<NUMBER>&exportFormat=docx", 
    { 
    headers: { 
     "Authorization" : "Bearer " + ScriptApp.getOAuthToken() 
    } 
    } 
); 

var blob = response.getBlob(); 

var resource = { 
    title: <DOCUMENT_TITLE>, 
    parents: [ 
    { 
     "id": <FOLDER_ID>, 
     "kind": "drive#fileLink" 
    } 
    ], 
    mimeType: 'application/vnd.google-apps.document' 
}; 

Drive.Files.update(resource, fileId, blob); 

This post给我暗示什么尝试。

相关问题