繁体   English   中英

从Google日历中检索事件

[英]Retrieving events from Google Calendar

我正在尝试检索Google日历的XML数据。 身份验证和检索都可行。 但是,当我检索事件时,gd:data不会作为协议参考文档包含在内( http://code.google.com/apis/calendar/data/2.0/developers_guide_protocol.html#RetrievingWithoutQuery

我正在遇到的一些错误消息取决于我如何引用属性为“startTime”的“when”节点(我在这个轶事中的最终目标)如下:

致命错误:当它看起来像'startTime'=> (string) $cal->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),节点不再存在'startTime'=> strval($cal->when->attributes()->startTime),

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

        [0] => SimpleXMLElement Object
            (
                [id] => http://www.google.com/calendar/feeds/braden.keith%40smartersys.com/private/full/7li4mr2c81mub1hcoqktn73fbo
                [published] => 2010-06-08T17:17:43.000Z
                [updated] => 2010-06-08T17:17:43.000Z
                [category] => SimpleXMLElement Object
                    (
                        [@attributes] => Array
                            (
                                [scheme] => http://schemas.google.com/g/2005#kind
                                [term] => http://schemas.google.com/g/2005#event
                            )

                    )

                [title] => title
                [content] => content
                [link] => Array
                    (
                        [0] => SimpleXMLElement Object
                            (
                                [@attributes] => Array
                                    (
                                        [rel] => alternate
                                        [type] => text/html
                                        [href] => https://www.google.com/calendar/hosted/smartersys.com/event?eid=N2xpNG1yMmM4MW11YjFoY29xa3RuNzNmYm8gYnJhZGVuLmtlaXRoQHNtYXJ0ZXJzeXMuY29t
                                        [title] => alternate
                                    )

                            )

                        [1] => SimpleXMLElement Object
                            (
                                [@attributes] => Array
                                    (
                                        [rel] => self
                                        [type] => application/atom+xml
                                        [href] => https://www.google.com/calendar/feeds/braden.keith%40smartersys.com/private/full/7li4mr2c81mub1hcoqktn73fbo
                                    )

                            )

                        [2] => SimpleXMLElement Object
                            (
                                [@attributes] => Array
                                    (
                                        [rel] => edit
                                        [type] => application/atom+xml
                                        [href] => https://www.google.com/calendar/feeds/braden.keith%40smartersys.com/private/full/7li4mr2c81mub1hcoqktn73fbo/63411700663
                                    )

                            )

                    )

                [author] => SimpleXMLElement Object
                    (
                        [name] => Braden Keith
                        [email] => braden.keith@smartersys.com
                    )

            )

根据这篇文章: http//www.sitepoint.com/blogs/2005/10/20/simplexml-and-namespaces/您必须使用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_gd = $cal->children('http://schemas.google.com/g/2005'); - 这定义了命名空间。 然后从那里, $ns_gd->when->attributes()->startTime从gd获取属性:当命名为startTime时。

男人,这是一个血腥的2天。 但我明白了。 希望这可以帮助有人在路上。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM