You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Google Apps Script添加日历参会者为文档编辑者时遇内部错误

解决方案

这个错误的核心原因是**Drive.Permissions.insert()接口不支持传入邮箱数组**,该接口一次只能处理单个用户的权限设置。测试时2个邮箱可能是偶然成功(或未触发批量校验),但批量传入数组直接违反接口规范,导致内部错误。

修正步骤

  1. 遍历参会者邮箱数组,逐个调用Drive.Permissions.insert()添加权限
  2. 添加请求间隔,避免触发Google API的速率限制

修正后的代码片段:

// 将事件参会者添加为新日程表的编辑者(逐个处理)
const editors = event.getGuestList().filter(guest => guest.getEmail() !== "").map(guest => guest.getEmail());
editors.forEach(email => {
  Drive.Permissions.insert(
    {
      role: 'writer',
      type: 'user',
      value: email 
    }, 
    newSheetId, 
    { 
      sendNotificationEmails: true,
      emailMessage: "Hi everyone, Attached here is the agenda for this week's meeting. Please take a few minutes between now and then to note some high-level projects and tasks which you worked on last week and some that you are tackling this week." 
    }
  );
  // 间隔1秒,避免API速率限制
  Utilities.sleep(1000);
});

额外注意事项

  • 确认脚本授权范围:高级Drive服务需要https://www.googleapis.com/auth/drive权限,部署时需确保授权已覆盖
  • 若团队人数较多,可改用Drive.Permissions.batchInsert()接口批量处理,效率更高
  • 检查是否有外部域邮箱参会者,部分企业域会限制外部用户的权限设置

内容的提问来源于stack exchange,提问作者Jeff A

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 07:45:00