如何使用 Google Calendar API 创建 Google Meet 链接?

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

我正在使用 Google Calendar API 在 Google Calendar API 中创建事件。这部分已经可以工作,但现在我正在尝试添加与该活动关联的 Google Meet 链接,但无法使其工作。这是代码:

const event = {
      'summary': eventName,
      'description': eventDescription,
      'attendees': [
        { 'email': emailFormatado }
      ],
      'start': {
        'dateTime': start.toISOString(),
        'timeZone': Intl.DateTimeFormat().resolvedOptions().timeZone
      },
      'end': {
        'dateTime': end.toISOString(), // Date.toISOString() ->
        'timeZone': Intl.DateTimeFormat().resolvedOptions().timeZone
      },
      'conferenceData': {
        'conferenceDataVersion': 1,
        'createRequest': {
          'requestId': 'sample123',
          'conferenceSolutionKey': { 'type': 'hangoutsMeet' },
        },
      }
    }

    await fetch("https://www.googleapis.com/calendar/v3/calendars/primary/events", {
      method: "POST",
      headers: {
        'Authorization': 'Bearer ' + session.provider_token
      },
      body: JSON.stringify(event)
    }).then((data) => {
      return data.json();
    }).then((data) => {
      console.log(data);
    });

我尝试弄乱请求和参数的顺序,仍然不起作用。创建的活动仍然缺少 Google Meet 链接

javascript reactjs google-api google-oauth google-calendar-api
1个回答
0
投票

在您的脚本中,请使用

'conferenceDataVersion': 1
作为查询参数。所以,请修改如下。

修改后的脚本:

const event = {
  'summary': eventName,
  'description': eventDescription,
  'attendees': [
    { 'email': emailFormatado }
  ],
  'start': {
    'dateTime': start.toISOString(),
    'timeZone': Intl.DateTimeFormat().resolvedOptions().timeZone
  },
  'end': {
    'dateTime': end.toISOString(), // Date.toISOString() ->
    'timeZone': Intl.DateTimeFormat().resolvedOptions().timeZone
  },
  'conferenceData': {
    'createRequest': {
      'requestId': 'sample123',
      'conferenceSolutionKey': { 'type': 'hangoutsMeet' },
    },
  }
}

await fetch("https://www.googleapis.com/calendar/v3/calendars/primary/events?conferenceDataVersion=1", {
  method: "POST",
  headers: {
    'Authorization': 'Bearer ' + session.provider_token
  },
  body: JSON.stringify(event)
}).then((data) => {
  return data.json();
}).then((data) => {
  console.log(data);
});

注:

  • 此修改假设您的访问令牌和变量值都是有效值。请注意这一点。

参考:

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