我正在使用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
获取事件计数。