google calendar api

How to insert an event onto secondary calendar using the google calendar api 2

With Zend Framework, I used their Gdata library to interface with the Google api. My application will be managing three separate calendars with the same Google account. Zend’s documentation does not tell you how to add an event to a calendar other than the default primary calendar. It’s not obvious with Google’s own API documentation either.

After some digging, I found the Zend_Gdata_Calendar::insertEvent() method accept a second optional parameter called $uri. There aren’t any comments or hints as to what this uri is for, but it is actually where you specify the calendar you’d like your event added to. How do you get the uri for your calendars? You need to query the api to get the information like below. Set your Google calendar login info in the below code and it will print your calendar uri’s to the screen. Use these uri’s as the second parameter to insertEvent().

$client = Zend_Gdata_ClientLogin::getHttpClient(GOOGLE_CALENDAR_USERNAME, GOOGLE_CALENDAR_PASSWORD, Zend_Gdata_Calendar::AUTH_SERVICE_NAME);
// 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) {
	echo '<br>calendar title: ' . $calendar->title->text;
	echo '<br>calendar uri: ' . $calendar->content->src;