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

如何扩展Google Calendar Event在事件弹窗中显示自定义属性?

Google Calendar事件弹窗添加自定义属性的实现方案

你要找的功能官方名称是Google Calendar Add-on 事件详情注入,具体实现步骤如下:

1. 调整Manifest配置

在appsscript.json里补充Calendar Add-on的事件触发配置,让脚本能响应事件弹窗打开的动作:

{
  "oauthScopes": [
    "https://www.googleapis.com/auth/calendar",
    "https://www.googleapis.com/auth/script.container.ui"
  ],
  "addOns": {
    "calendar": {
      "eventOpenTrigger": {
        "runFunction": "onEventOpen"
      },
      "currentEventAccess": "READ_WRITE"
    }
  }
}

2. 编写事件弹窗触发函数

实现onEventOpen函数,用CardService生成要嵌入事件弹窗的自定义内容——这些内容会直接出现在事件弹窗里,而非右侧面板:

function onEventOpen(e) {
  // 获取当前事件的自定义属性
  const targetEvent = CalendarApp.getCalendarById(e.calendarId).getEventById(e.eventId);
  const customValue = targetEvent.getExtendedProperties().get('your_custom_field_key');

  // 构建自定义卡片
  const infoSection = CardService.newCardSection()
    .addWidget(CardService.newTextParagraph().setText(`自定义属性:${customValue || '暂无数据'}`));
  
  const customCard = CardService.newCardBuilder()
    .setHeader(CardService.newCardHeader().setTitle('自定义信息'))
    .addSection(infoSection)
    .build();

  // 返回卡片,指定注入到事件弹窗
  return CardService.newCalendarEventActionResponseBuilder()
    .addCard(customCard)
    .build();
}

3. 同步自定义属性数据

如果需要在创建/编辑事件时保存自定义属性,可通过事件的扩展属性接口操作:

// 创建事件时设置自定义属性
function addCustomPropToEvent(eventId, calendarId) {
  const targetCalendar = CalendarApp.getCalendarById(calendarId);
  const targetEvent = targetCalendar.getEventById(eventId);
  targetEvent.getExtendedProperties().set('your_custom_field_key', '你要存储的自定义内容');
}

注意事项

  • 该功能仅针对Google Workspace账号的Add-on,个人账号需确认权限支持
  • 注入的自定义内容会显示在事件弹窗的「附加组件」标签页或直接嵌入详情区域(随Google UI布局调整)
  • 必须确保OAuth权限包含https://www.googleapis.com/auth/calendar,才能读写事件的扩展属性

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.14 23:22:26