如何使用getEvents()
方法的高级选项参数从来宾列表中具有特定电子邮件地址的日历中检索所有事件?
先感谢您
的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);
}