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;
}

Leave a Comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

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

  • Reply
    Dhaval

    Hello,

    I have found the way to update event in secondary calendar.

    There can be only one “organizer” as attendee in a meeting.
    You just need to add one guest as following

    $service = new Zend_Gdata_Calendar($this->_client);
    …..
    …..
    $oEvent->who[] = $service->newWho({URLDECODED_CALENDAR_ID}, “http://schemas.google.com/g/2005#event.organizer”, {CALENDAR_NAME});

    Thanks a lot