2017-01-12 45 views
0

我是日曆API的新手,並且有幾個基本問​​題。如何獲取其他所有者共享的Google日曆活動?

我想讓所有日曆上的其他用戶[email protected]與我分享的所有活動。她是主人,而不是我。

「此用戶擁有或訂閱爲0.0日曆」是響應當我運行這段代碼:

var calendar = CalendarApp.getCalendarsByName('[email protected]'); 
if(calendar == null){ 
//user may not have access, auto-subscribe them. 
calendar = CalendarApp.subscribeToCalendar('[email protected]', 
{hidden:true,selected:false}); 
} 
Logger.log('This user owns or is subscribed to %s calendars.', 
calendar.length); 

回答

0

的一種方式,我知道是列出自己所有的事件都有你正在尋找一個創造者對於。下面的函數將獲取您的事件並返回與事件創建者匹配的一組事件id。這不是一個包容性的解決方案,例如它沒有日期範圍或處理分頁結果,並且只是解決此問題的一種簡單方法。

https://developers.google.com/google-apps/calendar/v3/reference/events/list

function getEventIdsByCreator(calendarId,creator){ 
    return Calendar.Events.list(calendarId,{fields:"items/id,items/creator/email"}) 
      .items.filter(function(item){   
      try{if(item.creator.email === creator){return true}} 
      catch(e){} 
      }).map(function(item){return item.id}); 
}  

你會用它喜歡:

function myFunction(){ 
    var IDs = getEventIdsByCreator(myCalendarId,"[email protected]") 
} 
相關問題