Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Zend_GData Feed for a Specific Google Calendar

Tags:

I had a long detailed question about how to get a specific calendar's event feed, but figured (I think) a solution out before I posted. However, even with the solution I'm left wondering what I'm missing about this process. To get a single calendar's event feed (or to search that feed) I do the following:

  • Authenticate (obviously)
  • Get a list of Calendars: getCalendarListFeed();
  • Get the id property from one of the 'calendar' objects
  • Change: .../calendar/feeds/default/XXX%40YYY
  • To: .../calendar/feeds/XXX%40YYY/private/full
  • Pass that to getCalendarEventFeed() to query for that calendar.

Why do I have to manipulate the ID? It seems like the documentation for Zend_Gdata is spread over both Google's and Zend's sites. I haven't located a good reference on available properties from getCalendarListFeed(), so maybe I should grab something other than the ID?

It seems like there has to be more straightforward way - what am I missing here?

like image 495
Tim Lytle Avatar asked Oct 08 '09 02:10

Tim Lytle


2 Answers

I was looking for an answer to this same question and eventually came up with the following:

$service = Zend_Gdata_Calendar::AUTH_SERVICE_NAME;
$Client = Zend_Gdata_ClientLogin::getHttpClient('googleaccount','googlepass',$service);
$Service = new Zend_Gdata_Calendar($Client);

$Query = $Service->newEventQuery();
$Query->setUser('calendarid'); # As you know, you can obtain this with getCalendarListFeed()
$Query->setVisibility('public');
$Query->setProjection('full');
$Query->setOrderby('starttime');
$Query->setFutureevents('true');

The part that threw me off at first was that the "user" portion of the call is actually the calendar ID. Then you can do something like:

$events = $Service->getCalendarEventFeed($Query);
foreach ($events as $Event)
{
   // work with Event object here...
}

(The above should really be enclosed in a try/catch, but I'm too lazy to do that here.)

like image 27
bogeymin Avatar answered Oct 11 '22 11:10

bogeymin


You don't have to manipulate the ID.

If you look at the protocol guide, there's a <link rel="alternate" .../> element which contains the URL you want.

In the PHP client, you can retrieve this link by calling:

// $entry is an instance of Zend_Gdata_Calendar_ListEntry
$link = $entry->getAlternateLink()->getHref();

Also, the documentation you're looking for is here: http://framework.zend.com/apidoc/1.9/Zend_Gdata/Calendar/Zend_Gdata_Calendar_ListEntry.html

like image 113
Trevor Johns Avatar answered Oct 11 '22 10:10

Trevor Johns