Microsoft Graph SDK .NET 获取范围内的事件范围内、事件、Graph、Microsoft

2023-09-06 17:52:51 作者:萌萌的小确幸

我尝试使用以下代码获取一定范围内的所有事件

I tried to get all the events in a certain range using the following code

DateTime dateStart = DateTime.Parse("2018-07-20T11:00:00"), dateEnd = dateStart.AddDays(1);

List<QueryOption> options = new List<QueryOption>()
{
    new QueryOption("startDateTime", dateStart.ToUniversalTime().ToString()),
    new QueryOption("endDateTime", dateEnd.ToUniversalTime().ToString())
};

var eventsInRange = await graphClient.Me.Calendar.Events.Request(options).GetAsync();

但它会返回所有历史中的事件,而不仅仅是范围内的事件.有没有办法解决这个问题?

But it returns the events in all history, not only in range. Is there a way to solve this?

推荐答案

你调用的是 /events 端点使用 /calendarView 参数.你想使用 CalendarView 类:

var eventsInRange = await graphClient.Me
    .Calendar
    .CalendarView
    .Request(options)
    .GetAsync();