2016-02-29 131 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給我暗示什麼嘗試。

相關問題