我想知道是否有办法使用 Google Apps 脚本共享 Google 文档或 Google 表格,但以编程方式禁用文档上查看者/评论者的复制/下载功能?正常共享 Google 文档或表格时,您可以转到设置图标并取消选择这些选项:
但是我可以通过 Google Apps Script 做到这一点吗?
作为对此的后续行动,是否有任何方法也可以为编辑器禁用这些选项?我希望能够与某人共享文档,让他们成为编辑器,但阻止他们与其他人共享。谢谢你。
最佳答案
在这种情况下,如何使用 Drive API?我认为您可以使用 Drive API 设置它们。在这个答案中,使用了 Drive API v3 的“文件:更新”的方法。
示例脚本:
在您使用此脚本之前,please enable Drive API at Advanced Google services .
function myFunction() {
const fileId = "###"; // Please set the file ID.
const url = "https://www.googleapis.com/drive/v3/files/" + fileId;
const res = UrlFetchApp.fetch(url, {
method: "patch",
headers: {authorization: "Bearer " + ScriptApp.getOAuthToken()},
contentType: "application/json",
payload: JSON.stringify({viewersCanCopyContent: false, writersCanShare: false}),
});
console.log(res.getContentText())
// DriveApp.createFile(blob) // This comment line is used for automatically detecting the scope of "https://www.googleapis.com/auth/drive"
}
笔记:writersCanShare
用于“编辑者可以更改权限和共享”viewersCanCopyContent
用于“查看者和评论者可以看到下载、打印和复制的选项”viewersCanCopyContent
说 Warning: This item is deprecated. Deprecated - use copyRequiresWriterPermission instead.
.但是当 copyRequiresWriterPermission
使用,此检查无法控制。所以,在这个答案中,我使用了 viewersCanCopyContent
. {viewersCanCopyContent: false, copyRequiresWriterPermission: false, writersCanShare: false}
可能适合代替 {viewersCanCopyContent: false, writersCanShare: false}
. copyRequiresWriterPermission
可以使用,我认为Drive API v2可能可以使用它如下。但是我现在测试的时候,好像无法控制“查看者和评论者可以看到下载、打印和复制的选项”。 Drive.Files.patch({copyRequiresWriterPermission:false,writersCanShare:false}, fileId);
viewersCanCopyContent: true, writersCanShare: true
被使用,两个检查都被检查。引用:
关于google-apps-script - Google Apps Script,去掉复制/下载选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63664349/