如何获取其他所有者共享的 Google 日历活动



我是日历 API 的新手,有几个基本问题。

我想获取其他用户 tonya123456@gmail.com 与我共享的所有日历上的所有事件。 她是主人,不是我。

"此用户拥有或订阅了 0.0 日历"是我运行此代码时的响应:

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

我知道的一种方法是列出您自己的所有事件,这些事件具有您正在寻找的创建者。下面的函数将获取您的事件并返回与事件创建者匹配的事件 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,"tonya123456@gmail.com")
}

最新更新