从 googleCal 中的所有日历获取活动时间 api
Get event times from all calendars in googleCal api
我想做什么:
从工作日历中获取所有日历中所有事件的开始时间(如果它只是企业“所有者”所在的日历就没问题)。现在我已经连接到 'primary' 但我需要它包含所有内容。
calendar.events
.list({
auth: auth,
calendarId: CAL_ID,
timeMin: date,
showDeleted: false,
singleEvents: true,
maxResults: 20,
orderBy: 'startTime',
})
.then((data) =>
res.status(200).send(data),
)
查看文档后,似乎没有办法将多个日历 ID 放入 calendar.events.list。我不能只是 calendarId: [calId1,calId2].
这是否意味着我必须多次调用每个日历才能找到所有事件的时间?
附加信息:
我正在使用服务帐户,刚从 Oauth 切换过来,所以也许我可以做些其他事情。
检查此 thread. I as well checked the documentation for the calendars.events.list and it seems that the API call can only handle one calendarID per call, a solution would be that you make a calendarList.List 中是否存在与您的问题类似的问题,以检索您要查找的帐户的日历 ID,然后使用 calendars.events.list 循环每个 ID。
编辑:我能够运行此代码获取我帐户拥有的所有日历的 calendarID 并列出前 5 个事件:
function listCalendarEvents() {
var calendars;
var pageToken;
do {
calendars = Calendar.CalendarList.list({
maxResults: 100,
pageToken: pageToken
});
if (calendars.items && calendars.items.length > 0) {
for (var i = 0; i < calendars.items.length; i++) {
var calendar = calendars.items[i];
Logger.log('%s (ID: %s)', calendar.summary, calendar.id); // retrieves the calendar information along with the calendar ID
var calendarId = calendar.id; // assigning the calendar ID from the loop.
var now = new Date();
var events = Calendar.Events.list(calendarId, {
timeMin: now.toISOString(),
singleEvents: true,
orderBy: 'startTime',
maxResults: 5
});
if (events.items && events.items.length > 0) { //loop to retrieve the 5 events
for (var j = 0; j < events.items.length; j++) {
var event = events.items[j];
if (event.start.date) {
// All-day event.
var start = new Date(event.start.date);
Logger.log('%s (%s)', event.summary, start.toLocaleDateString());
} else {
var start = new Date(event.start.dateTime);
Logger.log('%s (%s)', event.summary, start.toLocaleString());
}
}
} else {
Logger.log('No events found.');
}
}
} else {
Logger.log('No calendars found.');
}
pageToken = calendars.nextPageToken;
} while (pageToken);
}
我想做什么:
从工作日历中获取所有日历中所有事件的开始时间(如果它只是企业“所有者”所在的日历就没问题)。现在我已经连接到 'primary' 但我需要它包含所有内容。
calendar.events
.list({
auth: auth,
calendarId: CAL_ID,
timeMin: date,
showDeleted: false,
singleEvents: true,
maxResults: 20,
orderBy: 'startTime',
})
.then((data) =>
res.status(200).send(data),
)
查看文档后,似乎没有办法将多个日历 ID 放入 calendar.events.list。我不能只是 calendarId: [calId1,calId2].
这是否意味着我必须多次调用每个日历才能找到所有事件的时间?
附加信息: 我正在使用服务帐户,刚从 Oauth 切换过来,所以也许我可以做些其他事情。
检查此 thread. I as well checked the documentation for the calendars.events.list and it seems that the API call can only handle one calendarID per call, a solution would be that you make a calendarList.List 中是否存在与您的问题类似的问题,以检索您要查找的帐户的日历 ID,然后使用 calendars.events.list 循环每个 ID。
编辑:我能够运行此代码获取我帐户拥有的所有日历的 calendarID 并列出前 5 个事件:
function listCalendarEvents() {
var calendars;
var pageToken;
do {
calendars = Calendar.CalendarList.list({
maxResults: 100,
pageToken: pageToken
});
if (calendars.items && calendars.items.length > 0) {
for (var i = 0; i < calendars.items.length; i++) {
var calendar = calendars.items[i];
Logger.log('%s (ID: %s)', calendar.summary, calendar.id); // retrieves the calendar information along with the calendar ID
var calendarId = calendar.id; // assigning the calendar ID from the loop.
var now = new Date();
var events = Calendar.Events.list(calendarId, {
timeMin: now.toISOString(),
singleEvents: true,
orderBy: 'startTime',
maxResults: 5
});
if (events.items && events.items.length > 0) { //loop to retrieve the 5 events
for (var j = 0; j < events.items.length; j++) {
var event = events.items[j];
if (event.start.date) {
// All-day event.
var start = new Date(event.start.date);
Logger.log('%s (%s)', event.summary, start.toLocaleDateString());
} else {
var start = new Date(event.start.dateTime);
Logger.log('%s (%s)', event.summary, start.toLocaleString());
}
}
} else {
Logger.log('No events found.');
}
}
} else {
Logger.log('No calendars found.');
}
pageToken = calendars.nextPageToken;
} while (pageToken);
}