如何将 Google Meet 和 Google Meet 直播网址导出到 Google sheet?

How to export Google Meet and Google Meet live stream urls to Google sheet?

所以我正在开发一个 App 脚本模板,该模板允许您查找日期范围内的 Google 日历并将其导出到 Google Spreadsheet 以供进一步报告或处理(托管在 https://www.cloudbakers.com/blog/export-google-calendar-entries-to-a-google-spreadsheet)。我的副本 运行 很好,但我想将 Google Meet 视频会议和 Google Meet Livestream 的网址添加到为每个日历输出的列事件。在我的公司,这些通常会列为 conferenceData.entryPoints[].uri 中的第一个和最后一个值。我试过了:

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(), events[i].conferenceData.entryPoints.uri]];

并得到“TypeError:无法从未定义中读取 属性 “entryPoints””。 Re-running 最后只有 events[i].conferenceData,实际上只是在 sheet.

的新专栏中打印“undefined”

关于我在这里遗漏的任何想法?我是 Apps 脚本新手,因此尝试自行解决此问题并没有取得多大成功。

当您使用 CalendarApp.getEvents(startTime, endTime, options) to get all the events within the given time range, It will return an array of CalendarEvent object. CalendarEvent 时 object 没有 conferenceData 方法。您可以在提供的参考 link 上查看可用的 CalendarEvent 方法列表。

没有CalendarEvent method you can use to obtain the Google Meet and Google Live Stream URLs. You need to use Advanced Calendar Service获取此网址。


Pre-requisite: Enable advanced services


示例代码:

  // 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');

  }

它有什么作用?

  1. 在您的header变量
  2. 中添加额外的sheetheader(“见面Link”和“直播”)
  3. 在您的 details 变量
  4. 中为会议 link 和直播 link 添加额外的默认值
  5. 从事件的 iCalUID 中获取日历事件 ID。 CalendarEvent.getId() returns 事件的 iCalUID。我们只需要去掉iCalUID中的“@google.com”即可得到事件id。

Note that the iCalUID and the event id used by the Calendar v3 API and Calendar advanced service are not identical and cannot be used interchangebly

  1. 使用 Calendar.Events.get(calendarId: string, eventId: string) to get the event resource 其中包含 conferenceData(如果可用)
  2. 检查conferenceData是否存在,根据entryPoints[]参数更新details变量
  3. 将活动详情写入活动sheet

输出: