使用指定的 Google Meet ID 创建一个 Google 日历活动,conferenceData.conferenceId

问题描述 投票:0回答:1

我想知道为什么以下函数会创建一个具有随机会议 ID 而不是我指定的

conferenceId
的事件。
conferenceId
无法按我的意愿进行编程设置?我可以通过点击 Google 日历中的活动来设置会议 ID。如何使用 Google API 以编程方式设置会议 ID?

https://developers.google.com/calendar/api/v3/reference/events#resource

function createEventWithConference() {
  const calendarId = "primary"; // Change to the desired calendar ID
  const conferenceId = "qsz-pkbc-tnx"; // Set the conference ID
  const event = {
    summary: 'Example Event',
    location: 'Online',
    description: 'This is an example event created with Google Calendar API',
    start: {
      dateTime: '2023-03-20T10:00:00',
      timeZone: 'America/New_York'
    },
    end: {
      dateTime: '2023-03-20T11:00:00',
      timeZone: 'America/New_York'
    },
    conferenceData: {
      createRequest: {
        conferenceSolutionKey: {
          type: 'hangoutsMeet'
        },
        requestId: Math.random().toString(36).substring(7),
      },
      conferenceId: conferenceId // Set the conference ID
    }
  };

  const response = Calendar.Events.insert(event, calendarId, {
    conferenceDataVersion: 1
  });

  Logger.log("Event created: %s", response.htmlLink);
}
javascript google-apps-script google-api google-calendar-api google-workspace
1个回答
0
投票

您提供的用于创建具有会议 ID 的活动的代码看起来是正确的。使用随机 Google Meet ID 而不是您设置的特定 ID 创建活动的原因可能是由于其他问题。

一个可能的原因可能是日历或用户帐户未启用 Google Meet 视频会议。您可以通过转到日历设置并在“活动设置”选项卡下检查 Meet 会议是否已启用,您应该会看到为视频会议启用 Meet 的选项。

另一个可能的原因可能是请求的会议 ID 无效或未被 Google 识别。您可以通过检查与会议 ID 关联的 Google Meet 链接来验证会议 ID 是否有效。

要使用 Google Calendar API 以编程方式设置 Meet ID,您可以创建一个新的会议 ID 并使用新的会议 ID 更新活动的 conferenceData。下面是使用 Google Calendar API 创建新会议和更新事件的示例代码:

    // Set the conference parameters
const conferenceRequest = {
    requestId: Math.random().toString(36).substring(7),
    conferenceSolutionKey: {
        type: 'hangoutsMeet'
    }
};

// Create a new conference using the Google Calendar API
const conferenceData = await gapi.client.calendar.events.create({
    calendarId: calendarId,
    conferenceDataVersion: 1,
    requestId: conferenceRequest.requestId,
    createRequest: conferenceRequest.createRequest
}).then((response) => {
    const conferenceId = response.data.conferenceData.conferenceId;
    return conferenceId;
}).catch((error) => {
    console.error('Error creating new conference:', error);
});

// Update the event with the new conference data
const eventPatch = {
    conferenceData: {
        conferenceId: conferenceData,
        createRequest: conferenceRequest
    }
};
gapi.client.calendar.events.patch({
    calendarId: calendarId,
    eventId: eventId,
    conferenceDataVersion: 1,
    resource: eventPatch
}).then((response) => {
    console.log('Event updated successfully:', response);
}).catch((error) => {
    console.error('Error updating event:', error);
});

此代码首先使用具有指定会议解决方案密钥的 calendar.events 资源的创建方法创建一个新会议。然后,它通过使用新的会议数据调用 calendar.events 资源的 patch 方法,用新的会议 ID 更新事件。

© www.soinside.com 2019 - 2024. All rights reserved.