![](/img/trans.png)
[英]Is it possible to publish a Google Apps Script Web App to G Suite Marketplace?
[英]Creating a Google Document shortcut in a G suite shared drive using Google App Script
我可以使用“我的云端硬盘”中的快捷方式或“我的云端硬盘”中的文件夹轻松创建 Google 文档文件的快捷方式。 这个问题和回复如何在 Google Drive Apps Script 中创建快捷方式而不是多个父项对此有很大帮助
但是,当我尝试对 G Suite 共享云端硬盘文件夹执行相同操作时,出现以下错误:
GoogleJsonResponseException:对 drive.files.insert 的 API 调用失败,错误:找不到文件:#FILE NUM
与“我的云端硬盘”(而非共享云端硬盘)一起使用的代码是:
function createShortcut() {
const targetId = "TARGET DOCUMENT ID";
const shortcutName = "Test";
const folderId = "TARGET FOLDER ID";
const resource = {
shortcutDetails: { targetId: targetId },
title: shortcutName,
mimeType:"application/vnd.google-apps.shortcut",
supportsTeamDrives:true,
parents: [{id: folderId}]
};
const shortcut = Drive.Files.insert(resource);
}
我已经查阅了文档: https : //developers.google.com/drive/api/v3/shortcuts没有运气。
您将在文件资源中包含supportsTeamDrives
参数。 首先,如文档中所示,不推荐使用此参数:您现在应使用supportsAllDrives
。 其次,请求正文(您称为resource
那个)和请求参数之间存在差异。
如果您查看Drive.Files.insert()
函数签名,您将看到有 3 个选项:
.insert(File resource)
;.insert(File resource, Blob mediaData)
;.insert(File resource, Blob mediaData, Object optionalArgs)
;您正在使用第一个,这不允许指定任何请求参数。 因此,您应该使用第三个。
以下是如何在您的情况下使用它:
// Since you are not creating nor uploading any file you shall leave the Blob mediatada parameter as null
const resource = {
shortcutDetails: { targetId: targetId },
title: shortcutName,
mimeType:"application/vnd.google-apps.shortcut",
parents: [{id: folderId}]
};
const options = { supportsAllDrives: true };
const shortcut = Drive.Files.insert(resource, null, options);
在这里找到https://groups.google.com/g/google-apps-script-community/c/bH-kn9UW_cg
添加支持所有驱动器设置为 true 的参数。 并确保您有权将文件添加到驱动器。 高级驱动器服务使用 v2 API。 您可以查看参考资料以获取更多详细信息。
let sheetFile = Drive.Files.insert( newFile, blob, { convert: true, supportsAllDrives: true } );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.