I’ve been trying to hook into the Google Calendar API to aggregate events from various calendars for a group of websites that I’m working on. I’ve pretty much got it figured out, except I can’t get the "setRecurrenceExpansionStart" or the "setStartMin" methods of the query object to work. My code is below (I also can’t seem to get the magicCookie to work either). Any ideas would be appreciated.
<?php
set_include_path('C:/wamp/www/ZendFramework-1.10.2/library/');
require_once( 'Zend/Gdata/Calendar.php');
require_once( 'Zend/Gdata/ClientLogin.php');
// Parameters for ClientAuth authentication
$service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
$user = "my_user_name";
$pass = "my_pass";
$eventArray = array();
$i=0;
// Create an authenticated HTTP client
$client = Zend_Gdata_ClientLogin::getHttpClient($user, $pass, $service);
// Create an instance of the Calendar service
$service = new Zend_Gdata_Calendar($client);
try {
$listFeed= $service->getCalendarListFeed();
}
catch (Zend_Gdata_App_Exception $e) {
//echo "Error: " . $e->getMessage();
}
foreach ($listFeed as $calendar) {
$calendarId = str_replace('http://www.google.com/calendar/feeds/default/', '', $calendar->id);
$calendarId = urldecode($calendarId);
$startDate='2010-03-01';
$endDate='2010-05-01';
$query = $service->newEventQuery();
//$query->setUser('default');
//$query->setUser('[email protected]');
$query->setUser($calendarId);
// Set to $query->setVisibility('private-magicCookieValue') if using MagicCookie auth
$query->setVisibility('public');
$query->setProjection('full');
$query->setOrderby('startTime');
$query->setFutureEvents('true');
$query->setSortOrder('ascending');
$query->setSingleEvents('true');
$query->setStartMin($startDate);
$query->setStartMax($endDate);
//$query->setRecurrenceExpansionStart('2005-08-09T10:57:00-05:00');
//$query->setRecurrenceExpansionEnd('2012-08-09T12:00:00-05:00');
// Retrieve the event list from the calendar server
try {
$eventFeed = $service->getCalendarEventFeed($query);
}
catch (Zend_Gdata_App_Exception $e) {
//echo "Error: " . $e->getMessage();
}
foreach ($eventFeed as $event) {
$campus = str_replace(' ', '_', $calendar->title);
foreach ($event->when as $when) {
$uniqueArrayKey = $when->startTime . '_' . $i;
}
$eventArray[$uniqueArrayKey][$campus]['event_title'] = $event->title->text;
foreach ($event->where as $where) {
$eventArray[$uniqueArrayKey][$campus]['event_location'] = $where->valueString;
}
foreach ($event->when as $when) {
$eventArray[$uniqueArrayKey][$campus]['event_starttime'] = $when->startTime;
$eventArray[$uniqueArrayKey][$campus]['event_endtime'] = $when->endTime;
}
$eventArray[$uniqueArrayKey][$campus]['event_content'] = $event->content->text;
$i++;
}// End foreach ($eventFeed as $event) {}
}// End foreach ($listFeed as $calendar) {}
function insensitive_uksort($a,$b) {
return strtolower($a)>strtolower($b);
}
uksort($eventArray, "insensitive_uksort");
print_r($eventArray);
?>
God does not save those who are only imaginary sinners. Be a sinner, and let your sins be strong, but let your trust in Christ be stronger, and rejoice in Christ who is the victor over sin, death, and the world.
I figured it out. When
$query->setFutureEvents();
is set to true, it overrides both
and $
query->setRecurrenceExpansionStart()
God does not save those who are only imaginary sinners. Be a sinner, and let your sins be strong, but let your trust in Christ be stronger, and rejoice in Christ who is the victor over sin, death, and the world.