谷歌幻灯片教程代码不会将所需的文件名应用于复制的文件



我正在按照谷歌的"数据合并"教程将数据从谷歌表单导入谷歌幻灯片,而不能完全工作的部分是"复制现有演示文稿"。当我运行提供的应用程序脚本代码时,我会得到一份名为"copy of…"而不是"New presentation title"的文件副本。

// Duplicate the template presentation using the Drive API.
var copyTitle = 'New presentation title';
var requests = {
name: copyTitle
};
var driveResponse = Drive.Files.copy({
resource: requests
}, originalpresentationID);
var presentationCopyId = driveResponse.id;
Logger.log(driveResponse.title) # Logger returns: "Copy of ..." 

如何使用所需名称正确创建现有文件的副本?教程好像错了。

我尝试过这样做,但遇到了同样的问题。看起来像个虫子。作为一种方法,请尝试在创建后重命名您的副本文件。这是代码。

var copyTitle = 'New presentation title';
var driveResponse = Drive.Files.copy({          
}, originalpresentationID);
var presentationCopyId = driveResponse.id;
var copyPPT = DriveApp.getFileById(presentationCopyId);
copyPPT.setName(copyTitle);

该示例中使用的代码混合了其他语言和客户端库中的一些语法。

Google应用程序脚本中的Drive"高级服务"使用Drive REST API的v2,其属性名称存在一些差异。值得注意的是,文件名是title,而不是name

此外,Drive.Files.copy请求中的drive#file资源(也称为元数据(的语法不是作为参数的子resource属性,而是直接作为参数:

const metadata = {
title: "new name",
// other properties
};
const options = {
// optional request parameters
// fields: "*",
};
var newFileMetaData = Drive.Files.copy(metadata, sourceId, options);

最新更新