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

Pri*_*iya 5 c# microsoft-teams microsoft-graph-api

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

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();
Run Code Online (Sandbox Code Playgroud)

上面的代码抛出异常,这是

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

我该如何解决这个错误?

小智 1

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

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