Php 从Google日历检索事件

Php 从Google日历检索事件,php,xml,kohana,simplexml,Php,Xml,Kohana,Simplexml,我正在尝试检索Google日历的XML数据。认证和检索所有作品。但是,当我检索事件时,gd:data并没有作为协议参考文档包含,它应该是() 根据我如何引用属性为“startTime”(本轶事中我的最终目标)的“when”节点,我遇到的一些错误消息如下: $xml = new SimpleXMLElement($this->get($url, $header)); $xml->asXML(); $calenda

我正在尝试检索Google日历的XML数据。认证和检索所有作品。但是,当我检索事件时,gd:data并没有作为协议参考文档包含,它应该是()

根据我如何引用属性为“startTime”(本轶事中我的最终目标)的“when”节点,我遇到的一些错误消息如下:

            $xml = new SimpleXMLElement($this->get($url, $header));
            $xml->asXML();

            $calendars = array();
            foreach ($xml->entry as $cal){
                    $ns_gd = $cal->children('http://schemas.google.com/g/2005');
                    $calendars[] = array(                            
                                                         'id'=>strval($cal->id),
                                                         'published'=>strval($cal->published),
                                                         'updated'=>strval($cal->updated),
                                                         'title'=>strval($cal->title),
                                                         'content'=>strval($cal->content),
                                                         'link'=>strval($cal->link->attributes()->href),
                                                         'authorName'=>strval($cal->author->name),
                                                         'authorEmail'=>strval($cal->author->email),
                                                         'startTime'=> strval($ns_gd->when->attributes()->startTime),
                                                        );
            }
致命错误:在第226行的…/googlecalendarwrapper.php中对非对象调用成员函数attributes() 当它看起来像
'startTime'=>(string)$cal->when->attributes()->startTime时,

GoogleCalendarWrapper_Model::getEventsList()[GoogleCalendarWrapper Model.getEventsList]:当节点看起来像
'startTime'=>strval($cal->when->attributes()->startTime),

strval()[function.strval]:当节点看起来像
'startTime'=>strval($cal->when->attributes()),
'startTime'=>strval($cal->when->attributes('startTime'),

代码如下所示:

            $xml = new SimpleXMLElement($this->get($url, $header));

            $calendars = array();
            foreach ($xml->entry as $cal){
                    $calendars[] = array(                            
                                                         'id'=>strval($cal->id),
                                                         'published'=>strval($cal->published),
                                                         'updated'=>strval($cal->updated),
                                                         'title'=>strval($cal->title),
                                                         'content'=>strval($cal->content),
                                                         'link'=>strval($cal->link->attributes()->href),
                                                         'authorName'=>strval($cal->author->name),
                                                         'authorEmail'=>strval($cal->author->email),
                                                         'startTime'=> strval($cal->when->attributes()),
                                                        );
            }
XML:


根据这篇文章: 使用SimpleXMLElement时,必须以稍微不同的方式处理名称空间。解决办法如下:

            $xml = new SimpleXMLElement($this->get($url, $header));
            $xml->asXML();

            $calendars = array();
            foreach ($xml->entry as $cal){
                    $ns_gd = $cal->children('http://schemas.google.com/g/2005');
                    $calendars[] = array(                            
                                                         'id'=>strval($cal->id),
                                                         'published'=>strval($cal->published),
                                                         'updated'=>strval($cal->updated),
                                                         'title'=>strval($cal->title),
                                                         'content'=>strval($cal->content),
                                                         'link'=>strval($cal->link->attributes()->href),
                                                         'authorName'=>strval($cal->author->name),
                                                         'authorEmail'=>strval($cal->author->email),
                                                         'startTime'=> strval($ns_gd->when->attributes()->startTime),
                                                        );
            }
注意
$ns\u gd=$cal->children('http://schemas.google.com/g/2005');-这定义了名称空间。然后,
$ns\u gd->when->attributes()->startTime
从gd:when命名为startTime时获取属性


伙计,这两天真是糟糕透了。但我明白了。希望这能对以后的人有所帮助。

根据本文: 使用SimpleXMLElement时,必须以稍微不同的方式处理名称空间。解决办法如下:

            $xml = new SimpleXMLElement($this->get($url, $header));
            $xml->asXML();

            $calendars = array();
            foreach ($xml->entry as $cal){
                    $ns_gd = $cal->children('http://schemas.google.com/g/2005');
                    $calendars[] = array(                            
                                                         'id'=>strval($cal->id),
                                                         'published'=>strval($cal->published),
                                                         'updated'=>strval($cal->updated),
                                                         'title'=>strval($cal->title),
                                                         'content'=>strval($cal->content),
                                                         'link'=>strval($cal->link->attributes()->href),
                                                         'authorName'=>strval($cal->author->name),
                                                         'authorEmail'=>strval($cal->author->email),
                                                         'startTime'=> strval($ns_gd->when->attributes()->startTime),
                                                        );
            }
注意
$ns\u gd=$cal->children('http://schemas.google.com/g/2005');-这定义了名称空间。然后,
$ns\u gd->when->attributes()->startTime
从gd:when命名为startTime时获取属性

伙计,这两天真是糟糕透了。但我明白了。希望这能对以后的人有所帮助