Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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("[email protected]",
        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

How can I solve this error?

like image 495
Priya Avatar asked Nov 06 '22 09:11

Priya


1 Answers

  • Make sure you use the latest NuGet Package and give a try. In order to get the latest one try the following:

"Install-Package Microsoft.Identity.Client -Pre". This command installs latest MSAL library.

  • Quickly i tested the sample. I know its not the BOT framework, but its MSAL & calling Graph, so the same logic applies and works on the principles. It worked for me.
  • Also i tested with BOT Framework and MSAL; here are the steps that i followed. You may want to check the same as well.
like image 107
Dev Avatar answered Nov 10 '22 00:11

Dev