0

如何使用getEvents()方法的高级选项参数从来宾列表中具有特定电子邮件地址的日历中检索所有事件?

先感谢您

4

1 回答 1

2

options参数getEvents()无法搜索事件的来宾列表。

这是一个函数,它将返回一个事件列表,其中仅包含来宾列表中具有指定电子邮件地址的事件。此功能也可作为 gist 使用

/**
 * Gets all events that occur within a given time range,
 * and that include the specified guest email in the
 * guest list.
 *
 * @param {Calendar} calen Calendar to search
 * @param {Date} start the start of the time range
 * @param {Date} end the end of the time range, non-inclusive
 * @param {String} guestEmail Guest email address to search for
 *
 * @return {CalendarEvent[]} the matching events
 */
function getEventsWithGuest(calen,start,end,guestEmail) {
  var events = calen.getEvents(start, end);
  var i = events.length;
  while (i--) {
    if (!events[i].getGuestByEmail(guestEmail)) {
      events.splice(i, 1);
    }
  }
  return events;
}

// Test function
function test_getEventsWithGuest() {
  var calen = CalendarApp.getDefaultCalendar();
  var now = new Date();
  // then... four weeks from now
  var then = new Date(now.getTime() + (4 * 7 * 24 * 60 * 60 * 1000));

  var events = getEventsWithGuest(calen,now,then,'guest@somewhere.com');

  Logger.log('Number of events: ' + events.length);
}
于 2013-05-09T11:27:14.523 回答