Skip to content

Instantly share code, notes, and snippets.

@Braunson
Last active August 29, 2015 14:22
Show Gist options
  • Save Braunson/c50ea4116a03e244aae5 to your computer and use it in GitHub Desktop.
Save Braunson/c50ea4116a03e244aae5 to your computer and use it in GitHub Desktop.
Checking freebusy on all Google Calendars for an authorized account.
<?php
// Create an authorized calendar service object
$calendarService = new Google_Service_Calendar( $client );
$calendarList = $calendarService->calendarList->listCalendarList();
$calendarArray = [];
// Put together our calendar array
while(true) {
foreach ($calendarList->getItems() as $calendarListEntry) {
$calendarArray[] = ['id' => $calendarListEntry->id ];
}
$pageToken = $calendarList->getNextPageToken();
if ($pageToken) {
$optParams = array('pageToken' => $pageToken);
$calendarList = $calendarService->calendarList->listCalendarList($optParams);
} else {
break;
}
}
// Make our Freebusy request
$freebusy = new Google_Service_Calendar_FreeBusyRequest();
$freebusy->setTimeMin('2015-06-01T00:00:00-04:00');
$freebusy->setTimeMax('2015-06-05T00:00:00-04:00');
$freebusy->setTimeZone('America/Eastern');
$freebusy->setItems( $calendarArray );
$createdReq = $calendarService->freebusy->query($freebusy);
// You will see each calendars and if there are any 'busy' items returned between the dates set.
var-dump($createdReq);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment