如何使用Microsoft图形API在日历中创建事件?

问题描述 投票:0回答:1

我已经使用bot框架4创建了bot,我正在使用图形API在日历中创建一个事件,但是它不起作用,

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 = "[email protected]",
                        Name = "ASDF VHFG"
                    },
                    Type = AttendeeType.Required
                }
            }
            };

            await graphClient.Me.Events
                .Request()
                .Header("Prefer", "outlook.timezone=\"Pacific Standard Time\"")
                .AddAsync(@event);
            String ss = "sere";

当控件进入等待状态时,它会抛出一个错误,如何解决? ,如何使用图形API预订会议室?

c# calendar azure-ad-graph-api
1个回答
0
投票

您为什么使用.WithTenantId("839291b6 - d335 - 4f0b - 93b0 - d4013318ea7d")?应该是.WithTenantId("839291b6-d335-4f0b-93b0-d4013318ea7d")。并且您正在使用UsernamePasswordProvider。因此,您应该像这样修改代码:await graphClient.Me.Events.Request().Header("Prefer", "outlook.timezone=\"Pacific Standard Time\"").WithUsernamePassword(username, s).AddAsync(@event);

不要忘记将密码添加到s。像这样: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');

© www.soinside.com 2019 - 2024. All rights reserved.