简体   繁体   中英

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

So I'm working off an App Script template that allows you to find and export your Google Calendar for a range of dates to a Google Spreadsheet for further reporting or processing (hosted at https://www.cloudbakers.com/blog/export-google-calendar-entries-to-a-google-spreadsheet ). I have it running just fine in my copy, but I want to add the urls for both the Google Meet video conference and the Google Meet Livestream to the columns that are output for each calendar event. At my company these would typically be listed as the first and last values in conferenceData.entryPoints[].uri. I tried:

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]];

and get "TypeError: Cannot read property "entryPoints" from undefined". Re-running with just events[i].conferenceData at the end, indeed just prints "undefined" in my new column in my sheet.

Any ideas on what I'm missing here? I'm an Apps Scripts noob so not having much success at all trying to troubleshoot this on my own.

When you use 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 doesn't have conferenceData method. You can check the list of available CalendarEvent methods on the reference link provided.

There is no CalendarEvent method you can use to obtain the Google Meet and Google Live Stream URLs. You need to use Advanced Calendar Service to obtain this URLs.


Pre-requisite: Enable advanced services

在此处输入图像描述

在此处输入图像描述


Sample Code:

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

  }

What it does?

  1. Add additional sheet header ("Meet Link" and "Live Stream") in your header variable
  2. Add additional default value for meet link and live stream link in your details variable
  3. Get the calendar event id from the iCalUID of the event. CalendarEvent.getId() returns an iCalUID of the event. We just need to remove "@google.com" in the iCalUID to obtain the event 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. Use Calendar.Events.get(calendarId: string, eventId: string) to get the event resource which contains the conferenceData (if available)
  2. Check if conferenceData exist, update the details variable based on the entryPoints[] parameter.
  3. Write the event details to the active sheet

Output:

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM