Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google apps script addViewer类DriveApp使用的方法始终将电子邮件发送给收件人。我可以禁用电子邮件吗?_Google Apps Script_Google Drive Api_Google Docs Api - Fatal编程技术网

Google apps script addViewer类DriveApp使用的方法始终将电子邮件发送给收件人。我可以禁用电子邮件吗?

Google apps script addViewer类DriveApp使用的方法始终将电子邮件发送给收件人。我可以禁用电子邮件吗?,google-apps-script,google-drive-api,google-docs-api,Google Apps Script,Google Drive Api,Google Docs Api,代码A和B执行相同的操作,但如果A在添加查看器时,addViewer命令不会将电子邮件发送给currentUser。相反,在案例B中,当添加查看器时,当前用户会收到文件共享的电子邮件 //CASE A var f = DocsList.getFolderById(folder.getId()); f.addViewer(currentUser); //CASE B var f = DriveApp.getFolderById(folder.getId()); f.addViewer(cur

代码A和B执行相同的操作,但如果A在添加查看器时,addViewer命令不会将电子邮件发送给currentUser。相反,在案例B中,当添加查看器时,当前用户会收到文件共享的电子邮件

//CASE A
var f = DocsList.getFolderById(folder.getId());  
f.addViewer(currentUser);

//CASE B
var f = DriveApp.getFolderById(folder.getId());
f.addViewer(currentUser);
我想与自动电子邮件共享,因为在程序结束时,我将发送一封自定义电子邮件(带有文件夹内的文件链接),如果程序成功完成,否则我将删除文件夹。
我该怎么办?文档列表将很快被弃用

如果您与Google脚本共享文件,电子邮件通知将始终发送给查看者和编辑。只有在Google Drive内手动共享文件时,才可以选择不发送该电子邮件。

要执行此操作,您需要使用[注意它不是DriveApp]以静默方式插入权限

该脚本通过暴露于Google Apps脚本。要使用它,你需要

完成后,您的权限插入代码可能如下所示:

/**
 * Insert a new permission without sending notification email.
 *
 * @param {String} fileId ID of the file to insert permission for.
 * @param {String} value User or group e-mail address, domain name or
 *                       {@code null} "default" type.
 * @param {String} type The value "user", "group", "domain" or "default".
 * @param {String} role The value "owner", "writer" or "reader".
 */
function insertSilentPermission(fileId, value, type, role) {
  var request = Drive.Permissions.insert({
    'value': value,
    'type': type,
    'role': role,
    'withLink': false
  },
  fileId,
  {
    'sendNotificationEmails': false
  });
}
我编辑了这个答案,将Laura的反馈包含在下面,因此它现在可以正常工作。

该方法需要大写字母“p”:Drive.Permissions.insert 但在这件小事之后,函数返回一个错误:

The numbers of arguments is invalid. Expected 2-3
我试过这个:

Drive.Permissions.insert(
{
  'role': 'reader',
  'type': 'user',
  'value': 'username@test.it'
},
fileId,  
{
  'sendNotificationEmails': 'false'
});
它可以正常工作,但只适用于文件。对于文件夹(在fileId中我放置了一个文件夹ID),发生了一件奇怪的事情:

在运行此代码之前,文件夹的共享设置为:

  • 仅与特定人员共享
  • person@example.com可以查看
  • admin@example.com是主人吗
运行文件夹的代码共享设置后,变为:

  • example.com中任何具有该链接的人都可以查看-->这是错误的
  • username@example.com可以查看-->这没问题
  • person@example.com可以查看
  • admin@example.com是主人吗