在 GAS 触发事件代码中,如何找出更新了哪个 Google 日历事件?
In GAS trigger event code, how to find out which Google calendar event was updated?
使用 Google Apps 脚本中的高级日历 API 服务 (https://developers.google.com/apps-script/advanced/calendar),我发现您可以在日历更新时调用事件处理函数(见屏幕截图),效果很好:每次添加或更改事件时,似乎都会调用我的函数。但是我无法弄清楚哪个日历事件(即约会)已被修改。使用 1 个类型为“事件”的 arg (e) 调用处理程序函数,但它似乎不包含 ID 或对更新的日历事件的任何引用。这是我的处理程序代码:
function triggeredOnUpdate(e){
Logger.log('Update event: %s', e);
var calendarId = 'primary';
var eventId = e.<????what goes here???>;
var event = Calendar.Events.get(calendarId, eventId);
Logger.log('Running update on Calendar Event: %s', event.summary);
colourEvent(calendarId, event);
}
日志输出为:
Update event: {authMode=FULL, calendarId=mycalendar@mydomain.com, triggerUid=1325034127}
TriggerUID 是触发器的 ID,因此每次调用此处理程序时都相同。
你知道我怎样才能知道更新了哪个日历事件吗?
(注意:当谈论日历中的触发器时,事件这个词被过度使用:有一个日历事件,如约会,以及更新事件,当约会被更改时)
]1
按照此工作流程获取事件 ID:
https://developers.google.com/apps-script/guides/triggers/events#eventupdated
总结:使用Calendar.Events.list
和你在函数参数中得到的日历地址进行全同步,其中包括nextSyncToken
可以保存在脚本属性中。
下次触发事件时,您可以通过提供 nextSyncToken
到 Calendar.Events.list
来执行增量同步。这将为您提供自上次同步以来的事件。
另请参阅:
https://developers.google.com/calendar/v3/reference/events/list
https://developers.google.com/calendar/v3/reference/events#resource
使用 Google Apps 脚本中的高级日历 API 服务 (https://developers.google.com/apps-script/advanced/calendar),我发现您可以在日历更新时调用事件处理函数(见屏幕截图),效果很好:每次添加或更改事件时,似乎都会调用我的函数。但是我无法弄清楚哪个日历事件(即约会)已被修改。使用 1 个类型为“事件”的 arg (e) 调用处理程序函数,但它似乎不包含 ID 或对更新的日历事件的任何引用。这是我的处理程序代码:
function triggeredOnUpdate(e){
Logger.log('Update event: %s', e);
var calendarId = 'primary';
var eventId = e.<????what goes here???>;
var event = Calendar.Events.get(calendarId, eventId);
Logger.log('Running update on Calendar Event: %s', event.summary);
colourEvent(calendarId, event);
}
日志输出为:
Update event: {authMode=FULL, calendarId=mycalendar@mydomain.com, triggerUid=1325034127}
TriggerUID 是触发器的 ID,因此每次调用此处理程序时都相同。
你知道我怎样才能知道更新了哪个日历事件吗?
(注意:当谈论日历中的触发器时,事件这个词被过度使用:有一个日历事件,如约会,以及更新事件,当约会被更改时)
按照此工作流程获取事件 ID: https://developers.google.com/apps-script/guides/triggers/events#eventupdated
总结:使用Calendar.Events.list
和你在函数参数中得到的日历地址进行全同步,其中包括nextSyncToken
可以保存在脚本属性中。
下次触发事件时,您可以通过提供 nextSyncToken
到 Calendar.Events.list
来执行增量同步。这将为您提供自上次同步以来的事件。
另请参阅: https://developers.google.com/calendar/v3/reference/events/list https://developers.google.com/calendar/v3/reference/events#resource