You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Google Calendar API为日历事件添加Google Meet链接?

解决Google Calendar API创建事件时无法添加Google Meet链接的问题

你的代码核心问题在于**conferenceDataVersion参数的位置放错了**——这个参数是请求级别的配置,必须作为URL查询参数传递,而不是嵌套在事件对象的conferenceData里。API只有看到这个查询参数,才会处理你创建Meet链接的请求。

修正步骤:

  • 把conferenceDataVersion=1追加到请求URL的末尾
  • 移除事件对象conferenceData里的conferenceDataVersion字段
  • 确保requestId是唯一值(避免重复请求导致的问题,可换成随机字符串)

修正后的完整代码:

const event = {
  'summary': eventName,
  'description': eventDescription,
  'attendees': [
    { 'email': emailFormatado }
  ],
  'start': {
    'dateTime': start.toISOString(),
    'timeZone': Intl.DateTimeFormat().resolvedOptions().timeZone
  },
  'end': {
    'dateTime': end.toISOString(),
    'timeZone': Intl.DateTimeFormat().resolvedOptions().timeZone
  },
  'conferenceData': {
    'createRequest': {
      'requestId': `${Date.now()}-${Math.random().toString(36).slice(2)}`, // 用时间戳+随机字符串生成唯一ID
      'conferenceSolutionKey': { 'type': 'hangoutsMeet' },
    },
  }
}

await fetch("https://www.googleapis.com/calendar/v3/calendars/primary/events?conferenceDataVersion=1", {
  method: "POST",
  headers: {
    'Authorization': 'Bearer ' + session.provider_token,
    'Content-Type': 'application/json' // 必须添加该请求头,确保JSON格式被正确解析
  },
  body: JSON.stringify(event)
}).then((data) => {
  return data.json();
}).then((data) => {
  console.log(data);
});

额外注意:

  • 确认你的授权token包含https://www.googleapis.com/auth/calendar.events权限,没有的话需要重新申请权限
  • 若仍有问题,可检查返回的API响应是否包含错误信息,根据提示排查

内容的提问来源于stack exchange,提问作者Hugo Hanashiro

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 23:25:17