在Django中创建Google Meet链接时报错:无效会议类型值
解决Google Calendar API创建Meet链接时的「Invalid conference type value」错误
问题代码及错误信息
获取服务账户凭证代码
SCOPES = ['https://www.googleapis.com/auth/calendar','https://www.googleapis.com/auth/calendar.events'] credentials = Credentials.from_service_account_file(path , scopes=SCOPES)
创建带Meet链接的事件代码
event = { "end": { "dateTime": "2023-12-29T11:00:00", "timeZone": "UTC" }, "start": { "dateTime": "2023-12-29T10:00:00", "timeZone": "UTC" }, "conferenceData": {"createRequest": {"requestId": "sample123", "conferenceSolutionKey": {"type": "hangoutsMeet"}}}, } event_response = service.events().insert(calendarId=calendarId, body=event,conferenceDataVersion=1).execute()
触发的错误
returned "Invalid conference type value.". Details: "[{'domain': 'global', 'reason': 'invalid', 'message': 'Invalid conference type value.'}]"
解决方案
错误根源是conferenceSolutionKey中的type值使用了已废弃的hangoutsMeet,当前Google Calendar API要求使用googleMeet作为会议类型标识。
修改事件体中的对应字段即可解决问题,修正后的代码如下:
event = { "end": { "dateTime": "2023-12-29T11:00:00", "timeZone": "UTC" }, "start": { "dateTime": "2023-12-29T10:00:00", "timeZone": "UTC" }, "conferenceData": {"createRequest": {"requestId": "sample123", "conferenceSolutionKey": {"type": "googleMeet"}}}, } event_response = service.events().insert(calendarId=calendarId, body=event,conferenceDataVersion=1).execute()
额外注意事项:
- 需确保服务账户邮箱已被添加为目标日历的共享成员,并授予足够权限(如「编辑」权限)
- 调用
insert方法时必须指定conferenceDataVersion=1,代码中已正确设置此参数
内容的提问来源于stack exchange,提问作者Rudraksh Dixit
相关产品推荐
相关产品推荐

