简体   繁体   中英

C# Microsoft Graph API obtain specific calendar

I'm using the new Microsoft Graph Core API v1.20.0 in a Visual Studio 2019 v16.4.5 C# project. I want to obtain all calendar entries ( Event s) of each office365 calendar separately.

So far I know, I can retrieve all calendars with await graphClient.Me.Calendars.Request().GetAsync(); and Events with

string startDate = DateTime.Now.AddMonths(-1).ToString("s");
string endDate = DateTime.Now.AddYears(1).ToString("s");
var queryOptions = new List<QueryOption>()
{
    new QueryOption("startDateTime", startDate),
    new QueryOption("endDateTime", endDate),
};

var resultPage = await graphClient.Me.Events.Request(queryOptions)
    .OrderBy("createdDateTime DESC")
    .GetAsync();

But I don't know how to iterate over all Calendars and obtaining all Events for each Calendar.

Me.Events will just return events from the main calendar for a User.

You will need to use Me.Calendars first as documented here https://docs.microsoft.com/en-us/graph/api/user-list-calendars?view=graph-rest-1.0&tabs=http

var calendars = await graphClient.Me.Calendars
    .Request()
    .GetAsync();

and for each calendar id you get back call list events https://docs.microsoft.com/en-us/graph/api/user-list-events?view=graph-rest-1.0&tabs=http

GET /me/calendars/{id}/events

which in the SDK would be

graphClient.Me.Calendars["calendar-id"].Events..Request()
        .GetAsync();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM