2013-05-09 71 views

回答

2

getEvents()options参数没有提供方法来搜索事件的客人名单。

这是一个函数,它将返回一个事件列表,该列表仅包含在来宾列表中包含指定电子邮件地址的事件。该功能也是available as a 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,'[email protected]'); 

    Logger.log('Number of events: ' + events.length); 
}