0

I have created bot using bot framework 4, I am creating an event in the calendar using graph API, but it is not working,

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";

when control goes at await graphclient it throws an error , how to solve it ? , how to book conerence room using graph api ?

Priya
  • 141
  • 4
  • 10
  • Any updates on this issue? – Allen Wu Feb 13 '20 at 10:18
  • @Allen Wu, I got an exception, InnerException {Microsoft.Graph.Auth.AuthenticationException: Code: generalException Message: Unexpected exception returned from MSAL. at Microsoft.Graph.User me = graphClient.Me.Request() .WithUsernamePassword("Tgj@indica.onmicrosoft.com", password) .GetAsync().Result; – Priya Feb 13 '20 at 10:21

1 Answers1

0

Why do you use .WithTenantId("839291b6 - d335 - 4f0b - 93b0 - d4013318ea7d")? It should be .WithTenantId("839291b6-d335-4f0b-93b0-d4013318ea7d"). And you are using UsernamePasswordProvider. So you should modify the code like this: await graphClient.Me.Events.Request().Header("Prefer", "outlook.timezone=\"Pacific Standard Time\"").WithUsernamePassword(username, s).AddAsync(@event);

Don't forget to add your password to s. Like this: 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');

Allen Wu
  • 15,529
  • 1
  • 9
  • 20
  • I got this error Microsoft.Identity.Client.MsalClientException: Only loopback redirect Uri is supported, but urn:ietf:wg:oauth:2.0:oob was found. Configure localhost or localhost:port both during app registration and when you create the PublicClientApplication object. See aka.ms/msal-net-os-browser for details, I have put localhost:3978 in redirect Uri, @ Allen Wu – Priya Feb 13 '20 at 11:20