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

使用Google Apps Script批量发送谷歌日历邀请时出现取消通知异常

问题原因及解决方案

问题根源

你当前的批量脚本每次调用Calendar.Events.patch时,仅传入单个参会者的数组,这会直接覆盖事件原有的参会者列表,而非追加新参会者:

  • 第一次循环:将参会者列表设为[user1],user1收到「活动创建」通知;
  • 第二次循环:将参会者列表替换为[user2],此时user1被移除,会收到「活动取消」通知,同时user2收到「活动创建」通知;
  • 若初始事件已有参会者或脚本重复执行,就会出现两人都收到两条通知的情况。

修复方案

方案一:一次性添加所有参会者(推荐)

通过一次API调用完成所有参会者的添加,避免多次修改导致的通知混乱:

function SendMultiple(calendarId, eventId) {
  const newGuests = ["user1@gmail.com","user2@gmail.com"];
  // 获取事件现有参会者(无则为空数组)
  const event = Calendar.Events.get(calendarId, eventId);
  const existingAttendees = event.attendees || [];
  // 合并现有参会者与新参会者(可过滤重复邮箱)
  const allAttendees = [
    ...existingAttendees,
    ...newGuests.map(email => ({ email }))
  ];
  // 一次性更新并发送通知
  Calendar.Events.patch(
    { attendees: allAttendees },
    calendarId,
    eventId,
    { sendUpdates: "all" }
  );
}

方案二:循环追加参会者(保留原有列表)

若需逐次添加,每次更新时需保留已添加的参会者:

function SendMultiple(calendarId, eventId) {
  const newGuests = ["user1@gmail.com","user2@gmail.com"];
  // 获取初始参会者列表
  let currentAttendees = Calendar.Events.get(calendarId, eventId).attendees || [];
  
  newGuests.forEach(email => {
    Utilities.sleep(10000);
    // 避免重复添加同一邮箱
    const isExisting = currentAttendees.some(attendee => attendee.email === email);
    if (!isExisting) {
      currentAttendees.push({ email });
      // 更新完整的参会者列表
      Calendar.Events.patch(
        { attendees: currentAttendees },
        calendarId,
        eventId,
        { sendUpdates: "all" }
      );
    }
  });
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.29 01:27:48