如何使用Zend_Gdata获取Google日历事件startime?

问题描述:

目前我正在开发项目,需要使用API​​访问Google Calenadar数据 - 一切正常,但我无法获取活动开始时间/结束时间 - 最重要的信息。如何使用Zend_Gdata获取Google日历事件startime?

我使用Zend框架和Zend_Gdata库,遗憾的是Zend的文档不是详细

如何获得所需的事件数据?或者,也许我应该使用另一个库?

这里是我让事件进给功能:

public function getEvents($future_only = TRUE,$force_refresh = FALSE) { 

    if (($this->events != NULL) && $force_refresh == FALSE) { 
     return $this->events; 
    } else { 
     if ($this->getService() != NULL) { 
      $service = $this->getService(); 
      try { 

       $query = $service->newEventQuery($this->url); 
       $query->setUser(null); 
       $query->setProjection(null); 
       $query->setVisibility(null); 
       $query->setOrderby('starttime'); 
       if ($future_only) { 
        $query->setFutureevents('true'); 
       } else { 
        $query->setFutureevents('false'); 
       } 

       $event_feed = $service->getCalendarEventFeed($query); 

       $this->events = $event_feed; 

       return $event_feed; 
      } catch (Exception $exc) { 
       . 
       . 
       . 
       return NULL; 
      } 
     } else { 
      return NULL; 
       } 
      } 
     } 

而且在那里我试图获取事件信息样本测试代码:

 $gcalendar = new Common_Model_GoogleCalendar(); 

      $events = $gcalendar->getEvents(); 

      if($events){ 

      foreach ($events as $evt) { 
       echo $evt->title.'<br />'; 
       echo $evt->id.'<br />'; 
       echo $evt->published.'<br />'; 
       Zend_Debug::dump($evt->getWhen());  //returns empty array 

      } 
      } 

不知道你是否有现在排序这一点,但除了@ Ashley的贡献,这是如何获得getWhen()工作:

$when = $evt->getWhen(); 
echo $when[0]->getStartTime(); 
echo $when[0]->getEndTime(); 

你的变量$events将是一个的Zend_Gdata_Calendar_EventEntry实例,它继承了Zend_Gdata_Kind_EventEntry,它具有功能getWhen

即:

$when = $evt->getWhen();

http://framework.zend.com/manual/en/zend.gdata.calendar.html

+0

不幸的是,这是我现在正在做的事情,似乎它不起作用 - 请参阅我的示例测试代码。 – stawek 2012-04-16 10:48:23