我正在尝试将新修订版本上传到现有文件(原始文件)并维护该文件的ID。
我在高级Google服务中启用了Google Drive API(v2)。我将脚本作为独立脚本使用(基于我读到的内容说Drive.Files.Update不适用于这些脚本,因此未附加到Google文档或电子表格中。)
在这行代码上:
Drive.Files.update({
title: currentFile.getName(), mimeType: currentFile.getMimeType()
}, originalFileID, blobOfNewContent);
我收到以下错误: 执行失败:很抱歉,发生服务器错误。请稍等,然后重试。 (第13行,文件“代码”)[总运行时间为8.215秒]
关于我还能尝试什么的任何线索?基本上,我需要维护文件的ID,只是经常从其他文件更新内容。
function overwriteFile(blobOfNewContent, originalFileID)
{
var currentFile;
currentFile = DriveApp.getFileById(originalFileID);
if (originalFileID != "")
{//If original File exsts
Drive.Files.update({
title: currentFile.getName(), mimeType: currentFile.getMimeType()
}, originalFileID, blobOfNewContent);
}
}
function getNewestSlidesInFolderAndUploadToStaticFileID()
{
// fileID of file that is "Original File"
var mainfileID = "some id";
var folders = DriveApp.getFoldersByName('Testing Slides');
var arryFileDates = [];
var objFilesByDate = {};
//find most recent file
while (folders.hasNext())
{
var folder = folders.next();
var files = folder.getFilesByType("application/vnd.google-apps.presentation");
while (files.hasNext())
{
var file = files.next();
// Make sure the fileID is not the static file
if (file.getId() != mainfileID)
{
var fileDate = file.getLastUpdated();
objFilesByDate[fileDate] = file.getId(); //Create an object of file names by file ID
arryFileDates.push(file.getLastUpdated());
} // end if id = mainfileID
} //end while (files.hasNext())
arryFileDates.sort(function(a, b) { return b - a});
var newestDate = arryFileDates[0];
Logger.log('Newest date is: ' + newestDate);
var newestFileID = objFilesByDate[newestDate];
Logger.log('newestFile: ' + newestFileID);
//return newestFile;
}//while folders.hasNext()
//Get the contents of the most recent file
var newestFile = DriveApp.getFileById(newestFileID);
var blob = newestFile.getBlob();
overwriteFile(blob, mainfileID);
//delete most recent file so that only the main file exists
newestFile.setTrashed(true);
}
我确实在stackoverflow上找到了所有这些代码,并且我只是修改了一些代码(硬编码)以满足我的需要。感谢原始编码人员的帮助。