Last active
August 29, 2015 14:22
-
-
Save Braunson/c50ea4116a03e244aae5 to your computer and use it in GitHub Desktop.
Checking freebusy on all Google Calendars for an authorized account.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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