我正在尝试在谷歌日历中创建视频通话,但 ConferenceData 数据为空,因为尚未创建任何数据,而且当我添加参与者时,我收到错误:服务日历引发了异常。 HttpStatusCode 被禁止。如果没有域范围的授权,服务帐户无法邀请与会者。但我已将服务帐户 ID 添加到 google Workspace 中的域中。
否则它可以正常工作,当我由于 API 产生异常而未添加与会者时,会创建日历。
Public Function createMeeting(meetInfo As Meetinfo) As IHttpActionResult
Try
' Se obtienen las credenciales iniciando sesion automaticamente con el usuario establecido
Dim credential As GoogleCredential = GetCredentials()
' Se crea el servicio de Google Calendar
Dim calendarService As New CalendarService(New BaseClientService.Initializer() With {.HttpClientInitializer = credential, .ApplicationName = "xxxx"})
' Creamos el evento de Google Calendar con la reunión de meet
Dim meetingEvent As New [Event] With {
.Summary = meetInfo.meetingTitle,
.Location = "Google Meet",
.Description = meetInfo.meetingDescription,
.ConferenceData = New ConferenceData() With {
.CreateRequest = New CreateConferenceRequest() With {
.RequestId = Guid.NewGuid().ToString()
}
},
.AnyoneCanAddSelf = True
}
Dim startTime As New EventDateTime()
startTime.DateTime = meetInfo.meetingDate
Dim endTime As New EventDateTime()
endTime.DateTime = meetInfo.meetingDate.AddHours(1)
meetingEvent.Start = startTime
meetingEvent.End = endTime
' Añadimos los participantes
Dim attendeesList As New List(Of EventAttendee)()
For Each attendee As String In meetInfo.attendees
Dim attendeeObject As New EventAttendee()
attendeeObject.Email = attendee
attendeesList.Add(attendeeObject)
Next
meetingEvent.Attendees = attendeesList
' Insertamos el evento en Google Calendar.
Dim calendarId As String = ConfigurationManager.AppSettings("meetCalendarId")
Dim request As EventsResource.InsertRequest = calendarService.Events.Insert(meetingEvent, calendarId)
request.ConferenceDataVersion = 1
'request.SendNotifications = True
Dim result As [Event] = request.Execute()
' Recuperamos el link de la reunión de meets
Dim meetLink As String = Nothing
If result.ConferenceData IsNot Nothing Then
For Each entryPoint In result.ConferenceData.EntryPoints
If entryPoint.EntryPointType = "video" Then
meetLink = entryPoint.Uri
Exit For
End If
Next
End If
Return Ok(meetLink)
Catch ex As Exception
Return InternalServerError(ex)
End Try
End Function
如果您配置了域范围委派。您需要记住使用 Create with user 来表示您在拨打电话时要模拟的用户。
Using stream = New FileStream(keyfilepath, FileMode.Open, FileAccess.Read)
credential = GoogleCredential.FromStream(stream).CreateScoped(Scopes).CreateWithUser("[email protected]")
End Using