当您使用CalendarApp.getEvents(startTime, endTime, options)获取给定时间范围内的所有事件时,它将返回一个CalendarEvent对象数组。CalendarEvent对象没有conferenceData
方法。您可以在提供的参考链接上查看可用的 CalendarEvent 方法列表。
没有可用于获取 Google Meet 和 Google Live Stream URL 的CalendarEvent方法。您需要使用高级日历服务来获取此 URL。
示例代码:
// Create a header record on the current spreadsheet in cells A1:N1 - Match the number of entries in the "header=" to the last parameter
// of the getRange entry below
var header = [["Calendar Address", "Event Title", "Event Description", "Event Location", "Event Start", "Event End", "Calculated Duration", "Visibility", "Date Created", "Last Updated", "MyStatus", "Created By", "All Day Event", "Recurring Event", "Meet Link", "Live Stream"]]
var range = sheet.getRange(1,1,1,16);
range.setValues(header);
// Loop through all calendar events found and write them out starting on calulated ROW 2 (i+2)
for (var i=0;i<events.length;i++) {
var row=i+2;
var myformula_placeholder = '';
// Matching the "header=" entry above, this is the detailed row entry "details=", and must match the number of entries of the GetRange entry below
// NOTE: I've had problems with the getVisibility for some older events not having a value, so I've had do add in some NULL text to make sure it does not error
var details=[[mycal,events[i].getTitle(), events[i].getDescription(), events[i].getLocation(), events[i].getStartTime(), events[i].getEndTime(), myformula_placeholder, ('' + events[i].getVisibility()), events[i].getDateCreated(), events[i].getLastUpdated(), events[i].getMyStatus(), events[i].getCreators(), events[i].isAllDayEvent(), events[i].isRecurringEvent(), "None", "None"]];
//Add Meet link
var eventId = events[i].getId().replace("@google.com","");
var currentEvent = Calendar.Events.get(mycal,eventId);
if(currentEvent.conferenceData != null){
//Update Meet link
details[0][14] = currentEvent.conferenceData.entryPoints[0].uri;
//Update Live Stream
if(currentEvent.conferenceData.entryPoints.length > 1){
details[0][15] = currentEvent.conferenceData.entryPoints[currentEvent.conferenceData.entryPoints.length - 1].uri;
}
}
var range=sheet.getRange(row,1,1,16);
range.setValues(details);
// Writing formulas from scripts requires that you write the formulas separate from non-formulas
// Write the formula out for this specific row in column 7 to match the position of the field myformula_placeholder from above: foumula over columns F-E for time calc
var cell=sheet.getRange(row,7);
cell.setFormula('=(HOUR(F' +row+ ')+(MINUTE(F' +row+ ')/60))-(HOUR(E' +row+ ')+(MINUTE(E' +row+ ')/60))');
cell.setNumberFormat('.00');
}
它能做什么?
header
在变量中添加额外的工作表标题(“Meet Link”和“Live Stream”)
details
在您的变量中添加额外的默认值以满足链接和直播链接
- 从事件的 iCalUID 获取日历事件 ID。CalendarEvent.getId()返回事件的 iCalUID。我们只需要删除 iCalUID 中的“@google.com”即可获取事件 ID。
请注意,日历 v3 API 和日历高级服务使用的 iCalUID 和事件 ID 不相同,不能互换使用
- 使用Calendar.Events.get(calendarId: string, eventId: string)获取包含(如果可用)的事件资源
conferenceData
- 检查是否
conferenceData
存在,details
根据entryPoints[]
参数更新变量。
- 将事件详细信息写入活动工作表
输出: