我的要求是使用ASP.NET和Google Calendar API生成一个Google Meet链接。我在Google Cloud中创建了一个服务帐户,并向后端提供了所有必需的凭据和权限。我附上了下面的代码,它成功地生成了一个Google Calendar事件,而没有Google Meet链接。但是当我向事件对象添加ConferenceData
属性时,我得到了一个“Bad request”错误。
这是我没有ConferenceData
属性的代码:
string[] Scopes = { CalendarService.Scope.Calendar };
string ApplicationName = "Google Calendar";
GoogleCredential credential;
using (var stream = new FileStream(Path.Combine(Directory.GetCurrentDirectory(), "Cre", "cred.json"), FileMode.Open, FileAccess.Read))
{
credential = GoogleCredential.FromStream(stream).CreateScoped(Scopes);
}
var services = new CalendarService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = ApplicationName,
});
var @event = new Event
{
Summary = "Tecoora Online Meeting",
Location = "Online/Google Meet",
Description = "Discussion with Lawyer",
Creator = new Event.CreatorData()
{
DisplayName = "Tecoora Google Meet",
Email = "[email protected]"
},
Organizer = new Event.OrganizerData()
{
DisplayName = "Tecoora Google Meet",
Email = "[email protected]"
},
Start = new EventDateTime()
{
DateTimeDateTimeOffset = timeSlot.FromTime,
},
End = new EventDateTime()
{
DateTimeDateTimeOffset = timeSlot.ToTime,
},
AnyoneCanAddSelf = true,
GuestsCanInviteOthers = true,
GuestsCanModify = true,
GuestsCanSeeOtherGuests = true,
Visibility = "public",
};
var eventRequest = services.Events.Insert(@event, "primary");
if(eventRequest == null)
{
response.Error = "Google Meet Link Generation Issue.";
response.Success = false;
return response;
}
eventRequest.ConferenceDataVersion = 1;
Event createdEvent = await eventRequest.ExecuteAsync();
if(createdEvent == null)
{
response.Error = "Google Meet Link Creation Issue.";
response.Success = false;
return response;
}
字符串
上面的代码成功地生成了Google日历事件。但是当我像下面的代码一样添加ConferenceData
时,我得到了一个“Bad request”。
这是事件,与会议数据:
var @event = new Event
{
Summary = "Tecoora Online Meeting",
Location = "Online/Google Meet",
Description = "Discussion with Lawyer",
Creator = new Event.CreatorData()
{
DisplayName = "Tecoora Google Meet",
Email = "[email protected]"
},
Organizer = new Event.OrganizerData()
{
DisplayName = "Tecoora Google Meet",
Email = "[email protected]"
},
Start = new EventDateTime()
{
DateTimeDateTimeOffset = timeSlot.FromTime,
},
End = new EventDateTime()
{
DateTimeDateTimeOffset = timeSlot.ToTime,
},
AnyoneCanAddSelf = true,
GuestsCanInviteOthers = true,
GuestsCanModify = true,
GuestsCanSeeOtherGuests = true,
Visibility = "public",
ConferenceData = new ConferenceData()
{
CreateRequest = new CreateConferenceRequest()
{
RequestId = Guid.NewGuid().ToString(),
ConferenceSolutionKey = new ConferenceSolutionKey()
{
Type = "hangoutsMeet"
}
}
}
型
这是来自Google日历API的错误:
{
"data": null,
"success": false,
"error": "The service calendar has thrown an exception. HttpStatusCode is BadRequest. Invalid conference type value."
}
型
我也改变了类型,并尝试- hangoutsMeet / eventNamedHangout。
这种改变对我也不起作用。
当我找到这个问题的解决方案时,一些Stackoverflow的答案建议在我的Google Workspace帐户中启用域范围的委托。但是我的Google Workspace帐户->安全性看不到域范围的委托选项。我以超级管理员身份登录Google Workspace。我附上了Google Workspace屏幕截图。x1c 0d1x
我需要找到解决这个问题的方法。请帮助我。
1条答案
按热度按时间70gysomp1#
您需要使用WITHUser来定义希望服务帐户在您的域名上模拟的用户。
字符串
Unlock the Power of Google Calendar in .NET with Domain-Wide Delegation!