5

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]

  • 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: https://developers.google.com/google-apps/calendar/v3/sync – luc Jun 02 '15 at 21:29
  • 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 Jun 03 '15 at 06:40
  • It's not endless, just somewhat lengthy.. You can paginate and actually reach the end ;) – luc Jun 05 '15 at 00:30
  • 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 Jun 05 '15 at 10:15

2 Answers2

3

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.

Reuben
  • 143
  • 1
  • 6
  • do you happen to know where does this 730 limit come from? I haven't found it anywhere in the doc but i can see this limit applied when i create a recurring event without the end date and a recurring event with the end date which is 2 year 1 month or so. – Andrey Stukalin Feb 17 '23 at 10:34
  • @AndreyStukalin I don't know where the 730 limit comes from. I assume Google didn't want to allow users to create arbitrary numbers of events and so came up with a limit that would feel like it ends "never." – Reuben Mar 06 '23 at 21:59
0

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

Brouwer
  • 651
  • 1
  • 4
  • 17