在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":"[email protected]","organizer":{"email":"[email protected]"},"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中获取事件名称,描述和其他与事件相关的详细信息?
您可以使用事件对象中提供的信息进行Calendar.Events: get
调用以获取事件的信息。
使用Apps脚本的CalendarApp
服务:
function onCalendarEventOpen(e) {
var event = CalendarApp.getCalendarById(e.calendarId).getEventById(e.id);
Logger.log(event.getTitle()); // Event name
Logger.log(event.getDescription()); // Event description
}
或者,使用Calendar Advanced服务:
function onCalendarEventOpen(e) {
var event = Calendar.Events.get(e.calendarId, e.id)
Logger.log(event.summary); // Event title
Logger.log(event.description); // Event description
}
如果使用此选项,请确保从Apps脚本UI的Resources > Advanced Google Services...
菜单项中启用Calendar Advanced服务。
希望对您有帮助!