通过Google Apps脚本更改文档的权限 [英] Change a document's permissions via Google Apps Script

查看:78
本文介绍了通过Google Apps脚本更改文档的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找示例脚本,该脚本根据传递给脚本的电子邮件地址和DocumentID重置外部电子表格上的默认权限。我打算创建一个脚本,该脚本可以解析电子邮件中的信息以获取DocumentID和电子邮件,将权限从默认更改为具有链接的任何人,然后通过该链接通过电子邮件发送地址。 / p>

看起来,perms是由DocList API控制的,我没有找到GAS与该API交互的示例。



执行此操作的脚本特别简单。例如

  function shareWithAnyoneAndEmail(documentID,email){
var sharedFolder = DocsList.getFolderById (身份证到您的 - 以前的共享文件夹);
var file = DocsList.getFileById(documentID);
file.addToFolder(sharedFolder);
MailApp.sendEmail(email,'这是你的文件',file.getName()+'\\\
'+ file.getUrl());
}


I'm looking for sample script that resets the default permissions on an external spreadsheet based on the email address and DocumentID passed to the script. I intent to create a script that can parse information from an email message to acquire the DocumentID and email, execute the permission change from default to anyone with a link, then email the passed address with that link.

It appears that perms are controlled by the DocList API and I'm not finding samples of GAS interacting with that API.

解决方案

AFAIK DocsList Services does not have a function to change the sharing mode, between private/anyone with a link/public, only to add/remove editors and viewers. But we can still achieve this by previously setting manually the share settings of a specific folder to "anyone with a link". Then, we have just to add the file to that folder to have it shared.

A script to do that is particularly simple. e.g.

function shareWithAnyoneAndEmail(documentID,email) {
  var sharedFolder = DocsList.getFolderById('id-to-your-previously-shared-folder');
  var file = DocsList.getFileById(documentID);
  file.addToFolder(sharedFolder);
  MailApp.sendEmail(email, 'Here is your file', file.getName()+'\n'+file.getUrl());
}

这篇关于通过Google Apps脚本更改文档的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆