Outlook 日历同步问题

阿杰·查图维迪

我正在使用 Microsoft 图形库来同步事件,但它始终返回前 10 个事件,但我的要求如下,1- 获取日期范围之间的事件计数。2-获取日期范围内的所有事件。

代码是,

 GraphServiceClient client = new GraphServiceClient(
                new DelegateAuthenticationProvider(
                    (requestMessage) =>
                    {
                        requestMessage.Headers.Authorization =
                            new AuthenticationHeaderValue("Bearer", accessToken);
                        if (!string.IsNullOrEmpty(userEmail))
                        {
                            requestMessage.Headers.Add("X-AnchorMailbox", userEmail);

                        }
                        return Task.FromResult(0);
                    }));


var eventResults = client.Me.Events.Request()
                        .GetAsync().Result;
迈克尔·赫夫纳格尔

如果要获取特定范围内的日历事件,则必须使用 calendarView(请参阅文档)。使用图形 SDK,它可能看起来像这样。

        List<Event> eventList = new List<Event>();
        List<QueryOption> options = new List<QueryOption>()
                        {
                            new QueryOption("startDateTime",startDateTime),
                            new QueryOption("endDateTime",endDateTime),
                            //new QueryOption("$top",top),
                            //new QueryOption("$select",select)
                        };

        var request = graphClient.Users[userId].Calendar.CalendarView.Request(options);

        var result = await request.GetAsync();

        if (result != null)
        {
            eventList.AddRange(result);

            var nextPage = result;
            while (nextPage.NextPageRequest != null)
            {
                var nextPageRequest = nextPage.NextPageRequest;
                nextPage = await nextPageRequest.GetAsync();
                if (nextPage != null)
                {
                    eventList.AddRange(nextPage);
                }
            }
        }

使用 获取事件计数eventList.Count

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章