如何获取其他所有者共享的 Google 个日历事件?
How to get Google calendar events shared by another owner?
我是日历的新手 api,有几个基本问题。
我想获取另一个用户 tonya123456@gmail.com 与我共享的所有日历上的所有事件。她是主人,不是我。
"This user owns or is subscribed to 0.0 calendars"是我运行这段代码时的响应:
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);
我知道的一种方法是列出您自己的所有活动,这些活动都有您正在寻找的创作者。下面的函数将获取您的事件和 return 与事件创建者匹配的事件 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")
}
我是日历的新手 api,有几个基本问题。
我想获取另一个用户 tonya123456@gmail.com 与我共享的所有日历上的所有事件。她是主人,不是我。
"This user owns or is subscribed to 0.0 calendars"是我运行这段代码时的响应:
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);
我知道的一种方法是列出您自己的所有活动,这些活动都有您正在寻找的创作者。下面的函数将获取您的事件和 return 与事件创建者匹配的事件 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")
}