Getting Zend_GData Feed for a Specific Google Calendar

早过忘川 提交于 2019-12-07 05:59:50

问题


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?


回答1:


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




回答2:


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.)



来源:https://stackoverflow.com/questions/1535361/getting-zend-gdata-feed-for-a-specific-google-calendar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!