【问题标题】:How to get Google Calendar event startime using Zend_Gdata?如何使用 Zend_Gdata 获取 Google 日历活动开始时间?
【发布时间】:2014-01-29 19:07:10
【问题描述】:

目前我正在处理需要使用 API 访问 Google 日历数据的项目 - 一切正常,但我无法获取事件开始时间/结束时间 - 最重要的信息。

我正在使用 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

            }
            }

【问题讨论】:

    标签: php zend-framework calendar gdata


    【解决方案1】:

    不确定您现在是否对此进行了排序,但除了@Ashley 的贡献之外,这是让getWhen() 工作的方法:

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

    【讨论】:

      【解决方案2】:

      您的变量$events 将是Zend_Gdata_Calendar_EventEntry 的一个实例,它继承了Zend_Gdata_Kind_EventEntry 的函数getWhen

      即:

      $when = $evt-&gt;getWhen();

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

      【讨论】:

      • 不幸的是,这就是我现在正在做的事情,而且似乎不起作用 - 请参阅我的示例测试代码。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-03
      • 2018-06-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多