在GAS触发事件代码中,如何找出更新了哪个Google日历事件?

问题描述 投票:1回答:1

在Google Apps脚本中使用高级日历API服务(https://developers.google.com/apps-script/advanced/calendar),我发现您可以在更新日历时调用事件处理函数(请参见屏幕截图),并且工作正常:每次添加事件或改变它似乎我的函数被调用。但是,我无法弄清楚哪个日历事件(即约会)已被修改。处理程序函数使用1 arg(e)调用,其类型为“event”,但它似乎不包含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);
}

并且日志输出是:

更新事件:{authMode = FULL,calendarId = [email protected],triggerUid = 1325034127}

TriggerUID是触发器的ID,因此每次调用此处理程序时都是相同的。

你知道我怎么知道哪个日历活动已被更新?

(注意:在谈论日历中的触发器时,单词事件会超载:有一个日历事件,比如和约会,以及更新事件,当更改该约会时)

events google-apps-script calendar google-calendar-api
1个回答
0
投票

按照此工作流程获取事件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

https://developers.google.com/apps-script/advanced/calendar

© www.soinside.com 2019 - 2024. All rights reserved.