Home > Software engineering >  Google Calendar API is not returning all events
Google Calendar API is not returning all events

Time:07-31

I have a query that displays 250 events that my local clubs calendar has added to their calendar.

It currently only goes up until 2021 which is not what I want. How do I get it to show current dates, do I have to change a setting or am I supposed to use the next page token?

$json = file_get_contents('https://www.googleapis.com/calendar/v3/calendars/'.$calName.'/events?key='.$key.'');

// Converts it into a PHP object
$data = json_decode($json, JSON_OBJECT_AS_ARRAY); 

$length = count($data['items']);
$i=0;

while ($length != $i){
     
    print_r($data['items'][$i]['start']);
    print_r("<br/>");

 $i   ; 

minimal output

CodePudding user response:

According to the Google Calendar API documentation for the maxResults optional query parameter:

Maximum number of events returned on one result page. […] By default the value is 250 events. The page size can never be larger than 2500 events.

So by default, a single request is limited to 250 events but you can increase this to 2500. You may need to set up paging even if you set the maxResults to the maximum 2500.

  • Related