问题
Is Microsoft Graph API calendarView limited to a single month? How can I get all events? Is there some implicit pagination?
I'm first checking the JSON output of events between 2017-01-01
and 2018-12-30
:
https://graph.microsoft.com/v1.0/me/calendar/calendarView?startDateTime=2017-01-01T00:00:00.0000000&endDateTime=2018-12-30T00:00:00.0000000
and list the dates
jq '.value[] .start .dateTime'
"2017-11-22T13:30:00.0000000"
"2017-11-23T14:00:00.0000000"
"2017-11-24T14:00:00.0000000"
"2017-11-27T10:00:00.0000000"
"2017-11-27T10:00:00.0000000"
"2017-11-27T11:00:00.0000000"
"2017-11-27T14:30:00.0000000"
"2017-11-28T09:00:00.0000000"
"2017-11-29T09:00:00.0000000"
"2017-11-29T14:00:00.0000000"
No calendar events from 12th month of 2017 for example! But I have them!
And then do a similar call for by narrowing the left end of dates range between 2017-12-01
and 2018-12-30
, and now I get:
"2017-12-01T12:30:00.0000000"
"2017-12-01T14:00:00.0000000"
"2017-12-04T08:30:00.0000000"
"2017-12-04T12:00:00.0000000"
"2017-12-06T09:00:00.0000000"
"2017-12-06T10:00:00.0000000"
"2017-12-07T13:00:00.0000000"
"2017-12-13T09:00:00.0000000"
"2017-12-13T09:00:00.0000000"
"2017-12-13T13:00:00.0000000"
I'm confused by List calendarView and List events documentation.
How can I get all of the events in my calendar, the ones that I can clearly see to exist in November and December of 2017, as well as in January, and February of 2018?
Do I have to call this API repeatedly for every month in a year? (I hope there's a single call I can make to get all the events in a year, or two years, after which I can filter, process, etc.)
回答1:
Difference between list events and list calendarView
When you list events (GET /me/events
), you get a non-expanded list of items in the calendar. What that means is that if you have recurring events, you would only get the series master in your results. It would be up to you to read the recurrence pattern and expand the event.
When you list a calendar view (GET /me/calendarview?...
), you get an expanded list of items. That means the server does the work to expand any recurring events and build a "view" of your calendar. So in this case if you have a recurring event, instead of getting the series master, you would get one or more occurrences of the series (depending on how many times it repeats in your view window). Because of this expansion work, you must provide a start and end time to put some sort of bounds on the call.
Another way of looking at it is the calendar view is more like what you're used to seeing when you view your calendar in Outlook.
So where's all my events?
I'm not aware of any specific limitation on the size of the window for a calendar view. (Not saying there isn't one, I'm just not aware of it). The more likely explanation is that you're not seeing all the events you expect because all API requests that return collections do have built-in paging. By default, you're limited to 10 items in the response. You should also see in your response an @odata.nextLink
, which is the URL you can use to request the next page of results (again, 10 being the default page size). You can increase your page size by using the $top
parameter, up to a maximum of 1000 (IIRC).
GET /me/calendar/calendarView?startDateTime=2017-01-01T00:00:00.0000000
&endDateTime=2018-12-30T00:00:00.0000000&$top=1000
来源:https://stackoverflow.com/questions/48686471/is-microsoft-graph-api-calendarview-limited-to-a-single-month-how-to-get-all-ev