如何扩展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
相关产品推荐
相关产品推荐

