3
votes

I would like to get all events of a recurring event.

Therefore I set the option singleEvents to true. Now, when I list all events, the response returns endless items (by using nextPageToken). Sure, I can set a MaxTime to have a maximum time limit.

However, I need the syncToken to get only updated events. Otherwise my server has a lot of synchronization tasks. :(

The server gets Push Notifications when something changed. When I create a recurring event, the server recieved the push notification and tries to get the updated events via the last syncToken (using list events).

How can I set a maximum time limit, so I can get the nextSyncToken without having endless nextPages.

My current call: GET https://www.googleapis.com/calendar/v3/calendars/[CALENDAR]/events?singleEvents=true&syncToken=[SYNC-TOKEN]

2
You can set the time boundaries on the initial request, get the whole range and then start using the sync token to get the updates. There is a guide with a code sample on it here: developers.google.com/google-apps/calendar/v3/syncluc
This does not work when during the sync a new endless recurring event was created, because when singleEvents is true I get endless items.Tobias Curth
It's not endless, just somewhat lengthy.. You can paginate and actually reach the end ;)luc
Do you know, how many items I get? And do I have to use the instance method to get events after the end? My current solution is to retrieve all events within an interval (including deleted ones). So our database is up-to-date within this interval.Tobias Curth

2 Answers

2
votes

When you use a sync token, GCal gives you all the updated events and the only way to limit the amount of events in each response is to use a pager. Set maxResults to limit the amount of results you get per page (max 2500) and then use pageToken until you get another nextSyncToken which means you are at the last page and there are no more events to sync. Each request will either have a nextSyncToken or nextPageToken but no both.

GCal creates 730 events for repeating events without some kind of limit, so 2 years worth of daily events or just under 61 years for a "first Friday of each month" type event. You can check this with the built in API and copying the results to somewhere you can search and count the instances of one of the keys. With defaults, 250 results per page with the 3rd page returning 230.

This isn't just how many are passed with events list and singleEvents true. You'll see in your GCal calendar that the events stop after this time and if you check back tomorrow there won't be another daily event that's been created.

Of course, there could be many long events since the last sync but since you're using push notifications this shouldn't affect you.

0
votes

Lately I have been dealing with a similar scenario and came up with this solution:

-set singleEvents to false

-for recurring events retrieve instances individually with timeMin and timeMax

Now you can still use syncTokens and the instances() part of the API let's you break up the recurring events into single events with a query. You just have to make sure you do a full sync if you are nearing timeMax again.

Source: https://developers.google.com/google-apps/calendar/v3/reference/events/instances