简体   繁体   English

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

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

I have created an auth provider using user-password auth provider but and trying to retrieve calendar events in bot code which is in c#, having bot framework 4我已经使用用户密码身份验证提供程序创建了一个身份验证提供程序,但并尝试在机器人代码中检索日历事件,该代码位于 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();

Above code throws exception which is上面的代码抛出异常是

Microsoft.graph.serviceexception code generalexceptionmessage an error occurred sending the request Microsoft.graph.serviceexception 代码 generalexceptionmessage 发送请求时发生错误

How can I solve this error?我该如何解决这个错误?

  • Make sure you use the latest NuGet Package and give a try.确保使用最新的 NuGet Package 并尝试一下。 In order to get the latest one try the following:为了获得最新的,请尝试以下操作:

"Install-Package Microsoft.Identity.Client -Pre". “安装包 Microsoft.Identity.Client -Pre”。 This command installs latest MSAL library.此命令安装最新的 MSAL 库。

The same issue in my case was caused by revoking the Task function by .GetAwaiter().GetResult() .在我的案例中,同样的问题是由.GetAwaiter().GetResult()撤销Task function 引起的。

Solution: I replaced the .GetAwaiter().GetResult() with await approach.解决方案:我用await方法替换了.GetAwaiter().GetResult()

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

相关问题 Microsoft.Graph.ServiceException:代码:methodNotAllowed - Microsoft.Graph.ServiceException: Code: methodNotAllowed Microsoft.Graph.ServiceException&#39; 代码:BadRequest 消息:当前经过身份验证的上下文对此请求无效 - Microsoft.Graph.ServiceException' Code: BadRequest Message: Current authenticated context is not valid for this request 尝试下载用户图像时出现 Microsoft.Graph.ServiceException - Microsoft.Graph.ServiceException when trying to download user image 发送请求时出错 - An error occurred while sending the request 如何在日历视图中展开日历事件中的 Microsoft Graph 扩展属性 - How to expand Microsoft Graph extended properties in calendar events in a calendar view HttpClient:“ HttpRequestException:发送请求时发生错误” - HttpClient: “HttpRequestException: An error occurred while sending the request” 发送请求时发生错误,post - An error occurred while sending the request, post 如何使用 Microsoft graph api 将 colors 应用于 outlook 日历事件? - How to apply colors to outlook calendar events using Microsoft graph api? HttpClient 抛出“发送请求时发生错误。” - HttpClient throwing "An error occurred while sending the request." Microsoft.Graph.ServiceException---&gt; System.Net.Sockets.SocketException。 同时获得 TransitiveMemberOf - Microsoft.Graph.ServiceException---> System.Net.Sockets.SocketException. while getting TransitiveMemberOf
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM