1

在appsscript.json 文件中,当eventOpenTrigger 动作触发时,会调用onCalendarEventOpen 函数。

 "calendar": {
       ....
      "currentEventAccess": "READ_WRITE", 
      "eventOpenTrigger": {
        "runFunction": "onCalendarEventOpen"
      },
      "eventUpdateTrigger": {
        "runFunction": "onCalendarEventUpdate"
      }
    }

在 onCalendarEventOpen 中,我完成了控制台日志以获取事件详细信息。

function onCalendarEventOpen(e){
  ...
  console.log(JSON.stringify(e));
  ...
}

从 console.log 中,我可以得到以下数据,其中包含参考、与会者等详细信息,但不包含事件名称、摘要、时间、位置详细信息。

{"calendar":{"capabilities":{"canSeeConferenceData":true,"canSeeAttendees":true,"canAddAttendees":true,"canSetConferenceData":true},"calendarId":"xyz@gmail.com","organizer":{"email":"xyz@gmail.com"},"id":"2a2gdhrpmcpm8rmav4s2sam8nc"},"userCountry":"","userLocale":"en","hostApp":"calendar","clientPlatform":"web","commonEventObject":{"userLocale":"en","hostApp":"CALENDAR","timeZone":{"offset":19800000,"id":"Asia/Kolkata"},"platform":"WEB"},"userTimezone":{"offSet":"19800000","id":"Asia/Kolkata"}}

如何在 eventOpenTrigger 中获取事件名称、描述和其他与事件相关的详细信息?

4

1 回答 1

2

回答:

您可以Calendar.Events: get使用事件对象中提供的信息进行调用以获取事件的信息。

代码片段:

使用CalendarAppApps Script 服务:

function onCalendarEventOpen(e) {
  var event = CalendarApp.getCalendarById(e.calendarId).getEventById(e.id);

  Logger.log(event.getTitle());        // Event name
  Logger.log(event.getDescription());  // Event description
}

或者,使用日历高级服务:

function onCalendarEventOpen(e) {
  var event = Calendar.Events.get(e.calendarId, e.id)

  Logger.log(event.summary);      // Event title
  Logger.log(event.description);  // Event description
}

如果您使用此选项,请确保从Resources > Advanced Google Services...Apps 脚本 UI 的菜单项中启用日历高级服务。

参考:

于 2020-04-21T07:43:44.367 回答