Problem
I need to pull exactly 12 public events from a public calendar via Javascript on client-side, or as many public events there are. Examples:
- calendar has 14 total events. 3 are private, so I expect 11.
- calendar has 18 total events. First 3 are private. I expect 12 events, not 9.
I have been using the Google Calendar API Explorer to little avail (link will take you to API explorer with the fields I've been using filled out). There doesn't seem to be anyway to tell the API to not include private events.
Note: I am executing this API call without OAuth. Events are posted using the Google Calendar web interface, so extended properties are out of the solution I believe. My public Google Calendar ID: [email protected]
A Bad Solution
If you look at the JSON response, you'll see that events that are private have the following property and value:
"visibility": "private"
What I can do is call the API with maxResults=12 and simply filter out any private events by checking for the JSON property above.
- If nextPageToken == null, calendar no longer has any events and the number of results retrieved is irrelevant.
- If nextPageToken != null and after filtering out private events I am left with fewer than 12 events, I can request another call to the Google Calendar API for the next 24 events (by passing in the non-null nextPageToken). If this response's nextPageToken != null, and the sum of the number of events from the last two calls does not equal 12, I can request the next 48 events, and so on until I have 12 public events.
The problem is I may have to call the Google Calendar API several times before I get the desired number of events. And I have to do this procedure for multiple calendars (e.g., if I have 4 public google calendars and each takes an average of 3 API calls to get 12 events, I'd be executing 12 different AJAX calls just to get the data ...). It is paramount that I get 12 events or until the calendar is exhausted.
A Good Solution
I can't find a good solution to this problem. I have scrutinized all the fields in the Google APIs Explorer to absolutely zero luck. Any help would be appreciated.