使用Google Apps Script添加日历参会者为文档编辑者时遇内部错误
解决方案
这个错误的核心原因是**Drive.Permissions.insert()接口不支持传入邮箱数组**,该接口一次只能处理单个用户的权限设置。测试时2个邮箱可能是偶然成功(或未触发批量校验),但批量传入数组直接违反接口规范,导致内部错误。
修正步骤
- 遍历参会者邮箱数组,逐个调用
Drive.Permissions.insert()添加权限 - 添加请求间隔,避免触发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
相关产品推荐
相关产品推荐

