繁体   English   中英

如何在获取日历事件时解决“Microsoft.graph.serviceexception 代码 generalexceptionmessage 发送请求时发生错误”?

[英]how to solve "Microsoft.graph.serviceexception code generalexceptionmessage an error occurred sending the request" while fetching calendar events?

我已经使用用户密码身份验证提供程序创建了一个身份验证提供程序,但并尝试在机器人代码中检索日历事件,该代码位于 c#,具有机器人框架 4

IPublicClientApplication publicClientApplication =
    PublicClientApplicationBuilder
        .Create("jhnjchdjvd")
        .WithTenantId("sdfdf")
        .Build();

var s = new SecureString();
s.AppendChar('<');
s.AppendChar('T');
s.AppendChar('N');
s.AppendChar('>');
s.AppendChar('7');

UsernamePasswordProvider authProvider = new UsernamePasswordProvider(publicClientApplication, scopes);

GraphServiceClient graphClient = new GraphServiceClient(authProvider);

Microsoft.Graph.User me = await graphClient.Me.Request()
    .WithUsernamePassword("kjkhv@indica.onmicrosoft.com",
        s).GetAsync();

var events = await graphClient.Me.Events
    .Request()
    .Header("Prefer", "outlook.timezone=\"Pacific Standard Time\"")
    .Select(e => new
    {
        e.Subject,
        e.Body,
        e.BodyPreview,
        e.Organizer,
        e.Attendees,
        e.Start,
        e.End,
        e.Location
    })
    .GetAsync();

上面的代码抛出异常是

Microsoft.graph.serviceexception 代码 generalexceptionmessage 发送请求时发生错误

我该如何解决这个错误?

  • 确保使用最新的 NuGet Package 并尝试一下。 为了获得最新的,请尝试以下操作:

“安装包 Microsoft.Identity.Client -Pre”。 此命令安装最新的 MSAL 库。

在我的案例中,同样的问题是由.GetAwaiter().GetResult()撤销Task function 引起的。

解决方案:我用await方法替换了.GetAwaiter().GetResult()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM