如何使用 Zend GData 解析重复事件?
有很多关于如何使用 Zend GData 从 Google Calendar 请求和解析事件列表的教程。
但所有教程都假设事件永远不会重复。 (某种程度上,他们描述了如何设置重复事件,但没有描述如何解析/显示它们。)
因此,我编写了一个脚本来将事件从 Google 日历复制到网站,但它不起作用,因为某些日历中的事件正在重复,并且教程中描述的方法会产生相当随机的输出。
有什么想法吗?
there are plenty of tutorials on how to request and parse a list of events from Google Calendar using Zend GData.
But all tutorials assume that events never repeat. (Kind of, they describe how to set up repeating events, but not how to parse / display them.)
So I wrote a script to copy events from Google Calendar to a web site, but it just doesn't work because some of the events in the calendar are repeating and the method described in the tutorials results in pretty random output.
Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我终于找到了你真正寻找的答案。根据 http://code.google.com/apis/calendar/ data/1.0/reference.html#Parameters,您需要将 'singleevents' 参数设置为 'true',强制返回的数据对重复事件进行自己的解析和排序。所以您的代码(基于 http://code.google.com /apis/calendar/data/1.0/developers_guide_php.html#RetrivingDateRange) 看起来像:
从此函数返回的数据有一个事件对于重复事件的每个实例,在所有其余“正常”事件中正确排序。重复规则的例外情况(例如单个事件取消)也得到正确反映。
所以我认为您现在可以使用该方法而无需任何注意事项或警告......它应该以您想要的方式为您提供您想要的数据。
您可能可以在没有第二个“foreach”循环的情况下完成此操作,因为现在每个事件应该只有一个“when”...将第 18-20 行替换为
但由于 Google 的示例确实包含第二个 foreach 循环,因此保留它可能更安全 希望现在为
您提供帮助还为时不晚!
I think I've finally found the answer you're really looking for. Per http://code.google.com/apis/calendar/data/1.0/reference.html#Parameters, you need to set the 'singleevents' parameter to 'true', forcing the data returned to do it's own parsing and ordering of recurring events. So your code (based on http://code.google.com/apis/calendar/data/1.0/developers_guide_php.html#RetrievingDateRange) will look something like:
The data that's returned from this function has a single event for each instance of your repeating events, ordered correctly among all the rest of the "normal" events. Exceptions to the recurrance rules (single event cancellations, for instance) are correctly reflected, as well.
So I think you can now use that method without any caveats or warnings...it should give you the data you want, in the way you want.
You can probably do it without the second "foreach" loop, since each event should only have one "when" now...replace lines 18-20 with
But since Google's example does include that second foreach loop, it's probably safer to leave it in.
Hope it's not too late to help you!