如何通过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
相关产品推荐
相关产品推荐

