I tried to figure out the same problem, and I believe that I have an answer.
The problem is that when Google calculates the "page" of events to return, it includes deleted events in this calculation, and your first page is filled with deleted events that you do not see if your query has "showDeleted" = True " .
I give the user the opportunity to "clear" their calendar and re-populate it and solve this problem. Consider this scenario:
The user has 250 events on his calendar and for arguments, say, the Googles page size is the same size.
When the user starts the process for refilling, these 250 events are deleted and 250 new events are created.
When we move to deleting events before the repopulate process, the first page returns without any events - this is because the first 250 in the list are those that were originally deleted. (I checked this with the API Explorer )
Using nextPageToken to get the next page of results works - as you already noted.
This is why creating a new calendar works for a certain period of time, that is, until you overcome this limit of the "page" and start returning 0 events in which we encounter problems.
Over time, and if the user repeatedly uses this repopulate function, their list of deleted events can become huge, and this will require many requests to return all events. (I don’t know how to delete all deleted events completely from Google Cal - they seem to stay forever)
I do not know how to return all events in one call. You need to go through the process, getting the page at a time, until the “NextPageToken” is returned. This makes sense, because for users who have huge calendars with 1000 appointments, it is inefficient to return in just one request.
Using the Google Calendar API V3, here is an example of what I use in VB.Net to remove all events. (Service - Google.Apis.Calendar.v3.CalendarService)
Private Sub ClearAllEvents() Dim pageToken As String = Nothing Dim events As Events Dim qry As New ListRequest(Service, GCalId) Do qry.PageToken = pageToken events = qry.Execute() For Each ev As [Event] In events.Items Dim dr As New DeleteRequest(Service, GCalId, ev.Id) dr.Execute() Next pageToken = events.NextPageToken Loop While Not IsNothing(pageToken) End Sub
gleng source share