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

使用Google Apps Script创建日历事件时添加自定义提醒的问题

解决Google日历事件自定义提醒不生效的问题

你的代码里reminders字段的格式完全错误,这就是自定义提醒没生效、默认提醒被触发的原因。要设置提前4周的自定义提醒,必须严格遵循Google Calendar API的结构要求:

正确的提醒字段结构

  1. 必须将useDefault设为false,禁用默认提醒规则
  2. 在overrides数组中定义自定义提醒,每个提醒对象需要包含两个属性:
    • method:提醒方式,可选值为popup(弹窗提醒)或email(邮件提醒)
    • minutes:提前提醒的分钟数,4周对应的分钟数计算正确:4*7*24*60 = 40320

修改后的完整代码

function createCalEvent(eventSummary, eventLoc, eventDesc, eventDate) {
  console.log("> createCalEvent");
  const calendarId = 'primary';
  console.log(">> Summary: " + eventSummary);
  console.log(">> Location: " + eventLoc);
  console.log(">> Description: " + eventDesc);
  console.log(">> Date: " + eventDate);
  console.log(">> Calendar: " + calendarId);

  // event details for creating event.
  let event = {
    summary: eventSummary,
    location: eventLoc,
    description: eventDesc,
    start: {
      date: eventDate // 格式必须为 "YYYY-MM-dd"
    },
    end: {
      date: eventDate
    },
    colorId: 11,  // 红色背景
    reminders: {
      useDefault: false,
      overrides: [
        {
          method: 'popup', // 可替换为 'email' 选择邮件提醒
          minutes: 40320
        }
      ]
    }
  };

  // 完成事件插入(补充你原代码中可能存在的API调用逻辑)
  try {
    const createdEvent = Calendar.Events.insert(event, calendarId);
    console.log("事件创建成功:" + createdEvent.htmlLink);
  } catch (error) {
    console.error("创建事件失败:" + error.message);
  }
}

关键说明

  • 必须设置useDefault: false,否则即使定义了overrides,系统仍会使用默认提醒
  • 如果需要多种提醒方式(比如弹窗+邮件),可以在overrides数组中添加多个对象
  • 全天事件的提醒时间以事件当天0点为基准,提前4周的提醒会在事件日期前28天的0点触发

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.22 00:28:27