2012-04-12 102 views
0

目前我正在開發項目,需要使用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 

      } 
      } 

回答

5

不知道你是否有現在排序這一點,但除了@ Ashley的貢獻,這是如何獲得getWhen()工作:

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

你的變量$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

相關問題