0

我正在使用 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;
4

1 回答 1

2

如果您想获取特定范围内的日历事件,您必须使用 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

于 2018-08-13T06:26:00.240 回答