【问题标题】:How to add a Google Meet link to a new Google Calendar Event using a Google Apps Script?如何使用 Google Apps 脚本将 Google Meet 链接添加到新的 Google 日历活动?
【发布时间】:2020-09-17 03:06:30
【问题描述】:

我引用了 https://cloud.google.com/blog/products/application-development/hangouts-meet-now-available-in-google 和 https://developers.google.com/calendar/v3/reference/events,但似乎不知道如何以编程方式将 Google Meet 链接添加到 Google 日历活动。这是我的 Google Apps 脚本代码:

/**
 * Creates an event in the user's default calendar.
 */
function createEvent() {
  var calendarId = 'primary';
  var start = getRelativeDate(1, 12);
  var end = getRelativeDate(1, 13);
  var event = {
    summary: 'Test Event',
    description: 'Test.',
    start: {
      dateTime: start.toISOString()
    },
    end: {
      dateTime: end.toISOString()
    },
    attendees: [
      {email: 'XXXXXX@XXXX.XXX'},
    ],
      conferenceData: {createRequest: {conferenceSolutionKey: {type: 'hangoutsMeet'}}}
  };
      event = Calendar.Events.insert(event, calendarId, {sendNotifications: true, conferenceDataVersion: 1}  );
  Logger.log('Event ID: ' + event.id);
}

/**
 * Helper function to get a new Date object relative to the current date.
 * @param {number} daysOffset The number of days in the future for the new date.
 * @param {number} hour The hour of the day for the new date, in the time zone
 *     of the script.
 * @return {Date} The new date.
 */
function getRelativeDate(daysOffset, hour) {
  var date = new Date();
  date.setDate(date.getDate() + daysOffset);
  date.setHours(hour);
  date.setMinutes(0);
  date.setSeconds(0);
  date.setMilliseconds(0);
  return date;
}

感谢任何帮助。谢谢!

【问题讨论】:

  • 官方文档说You can create a new conference for an event by providing a createRequest with a newly generated requestId which can be a random string.。 Ref 由此看来,创建类似conferenceData: {createRequest: {requestId: Utilities.getUuid(), conferenceSolutionKey: {type: 'hangoutsMeet'}}} 的新会议似乎需要包含requestId。

标签: javascript google-apps-script google-api google-calendar-api google-meet


【解决方案1】:

我已成功使用此代码创建活动并使用文本变量“summary”、“id”返回 Meet 链接;和日期变量“开始”和“结束”:

var event = {
  "summary": summary,
 "start": {
   "dateTime": start.toISOString()
     },
  "end": {
    "dateTime": end.toISOString()
      },
       "conferenceData": {
          "createRequest": {
           "conferenceSolutionKey": {
             "type": "hangoutsMeet"
         },   
           "requestId": id
          }
     }
  };

 event = Calendar.Events.insert(event, 'primary', {
   "conferenceDataVersion": 1});
 return event.hangoutLink;

【讨论】:

    猜你喜欢
    • 2020-10-17
    • 1970-01-01
    • 2022-11-19
    • 1970-01-01
    • 2016-09-17
    • 2014-03-31
    • 2012-04-22
    • 2021-12-10
    相关资源
    最近更新 更多