我已经使用bot框架4创建了bot,我正在使用graph API在日历中创建一个事件,但是它不起作用,
IPublicClientApplication publicClientApplication = PublicClientApplicationBuilder
.Create("2c4c8826-dc0d-42e2-9d87-190b4bbb2ec2")
.WithTenantId("839291b6 - d335 - 4f0b - 93b0 - d4013318ea7d")
.Build();
var s = new SecureString();
UsernamePasswordProvider authProvider = new UsernamePasswordProvider(publicClientApplication, scopes);
GraphServiceClient graphClient = new GraphServiceClient(authProvider);
var @event = new Event
{
Subject = "Let's go for lunch",
Body = new ItemBody
{
ContentType = BodyType.Html,
Content = "Does late morning work for you?"
},
Start = new DateTimeTimeZone
{
DateTime = "2020-02-15T12:00:00",
TimeZone = "Pacific Standard Time"
},
End = new DateTimeTimeZone
{
DateTime = "2020-02-15T14:00:00",
TimeZone = "Pacific Standard Time"
},
Location = new Location
{
DisplayName = "Harry's Bar"
},
Attendees = new List<Attendee>()
{
new Attendee
{
EmailAddress = new EmailAddress
{
Address = "temp123@indica.onmicrosoft.com",
Name = "ASDF VHFG"
},
Type = AttendeeType.Required
}
}
};
await graphClient.Me.Events
.Request()
.Header("Prefer", "outlook.timezone=\"Pacific Standard Time\"")
.AddAsync(@event);
String ss = "sere";
当控件进入等待状态时,graphclient会引发错误,该如何解决? ,如何使用图形API预订会议室?
答案 0 :(得分:0)
您为什么使用.WithTenantId("839291b6 - d335 - 4f0b - 93b0 - d4013318ea7d")
?它应该是.WithTenantId("839291b6-d335-4f0b-93b0-d4013318ea7d")
。您正在使用UsernamePasswordProvider
。因此,您应该这样修改代码:await graphClient.Me.Events.Request().Header("Prefer", "outlook.timezone=\"Pacific Standard Time\"").WithUsernamePassword(username, s).AddAsync(@event);
请不要忘记将密码添加到s
。像这样:var s = new SecureString(); s.AppendChar('d'); s.AppendChar('u'); s.AppendChar('m'); s.AppendChar('b'); s.AppendChar('p'); s.AppendChar('a'); s.AppendChar('s'); s.AppendChar('s'); s.AppendChar('w'); s.AppendChar('d');