问题描述
我正在尝试通过CalDAV获取iCloud日历的日历活动来快速找到空闲/忙碌时间。我可以获取可用的日历,并根据或使用获取给定日期范围的日历信息应该与将此REPORT xml请求发送到日历网址一样简单(即):
< c:calendar-query xmlns:d =DAV:xmlns:c =urn:ietf:params:xml:ns:caldav>
< d:prop>
< d:getetag />
< c:calendar-data />
< / d:prop>
< c:comp-filter name =VCALENDAR>
< C:comp-filter name =VEVENT>
< C:time-range start =20131115T000000Zend =20131201T000000Z/>
< / C:comp-filter>
< / c:comp-filter>
< / c:filter>
< / c:calendar-query>
这实际上是 GetEvents()函数在DAViCal库中。但我只是得到回复中每个日历项的网址,而不是日历数据本身:
< ;? xml version ='1.0'encoding ='UTF-8'?>< multistatus xmlns ='DAV:'>
< Response>
< href> / .. userid ../ calendars / work / 8D2D90EB-BD23-4137-AD22-70D971C587F2.ics< / href>
< propstat>
< prop>
< getetag>C = 7734 @ U = b09ce345-d654-491e-bb4a-55358e7019d9< / getetag>
< getcontenttype> text / calendar< / getcontenttype>
< / prop>
< status> HTTP / 1.1 200 OK< / status>
< / propstat>
< / response>
< response>
< href> / .. userid ../ calendars / work / AA2385AB-EA58-4625-AF87-6D4FB9405686.ics< / href>
< propstat>
< prop>
< getetag>C = 7733 @ U = b09ce345-d654-491e-bb4a-55358e7019d9< / getetag>
< getcontenttype> text / calendar< / getcontenttype>
< / prop>
< status> HTTP / 1.1 200 OK< / status>
< / propstat>
< / response>
...
< / multistatus>
我当然可以为每个单独的日历项目进行GET请求,但显然这是很慢的。解决方案如果您只添加
< c:calendar-data />
和
< d:getetag />请求中的
,如下所示:
< c:calendar-query xmlns:d =DAV:xmlns:c =urn:ietf:params:xml:ns:caldav>
< d:prop>
< c:calendar-data />
< / d:prop>
< c:filter>
< c:comp-filter name =VCALENDAR>
< C:comp-filter name =VEVENT>
< C:time-range start =20131115T000000Zend =20131201T000000Z/>
< / C:comp-filter>
< / c:comp-filter>
< / c:filter>
< / c:calendar-query>
: - )
I'm attempting to quickly find free/busy time by fetching the calendar events for an iCloud calendar via CalDAV. I'm able to get the available calendars, and according to documentation here or using the DAViCal client library fetching the calendar information for a given date range should be as simple as sending this REPORT xml request to a calendar URL (ie. https://caldav.icloud.com/..userid../calendars/work/):
<c:calendar-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav"> <d:prop> <d:getetag /> <c:calendar-data /> </d:prop> <c:filter> <c:comp-filter name="VCALENDAR"> <C:comp-filter name="VEVENT"> <C:time-range start="20131115T000000Z" end="20131201T000000Z"/> </C:comp-filter> </c:comp-filter> </c:filter> </c:calendar-query>which is essentially what the GetEvents() function does in the DAViCal library. However I'm just getting the URL for each calendar entry in the reply, rather than the calendar data itself:
<?xml version='1.0' encoding='UTF-8'?><multistatus xmlns='DAV:'> <response> <href>/..userid../calendars/work/8D2D90EB-BD23-4137-AD22-70D971C587F2.ics</href> <propstat> <prop> <getetag>"C=7734@U=b09ce345-d654-491e-bb4a-55358e7019d9"</getetag> <getcontenttype>text/calendar</getcontenttype> </prop> <status>HTTP/1.1 200 OK</status> </propstat> </response> <response> <href>/..userid../calendars/work/AA2385AB-EA58-4625-AF87-6D4FB9405686.ics</href> <propstat> <prop> <getetag>"C=7733@U=b09ce345-d654-491e-bb4a-55358e7019d9"</getetag> <getcontenttype>text/calendar</getcontenttype> </prop> <status>HTTP/1.1 200 OK</status> </propstat> </response> ... </multistatus>I can of course do a GET request for each individual calendar item, but obviously this is quite slow. Is there a trick to getting the calendar data downloaded in one request?
解决方案It works if you just include
<c:calendar-data />and NOT
<d:getetag />in the request, like this:
<c:calendar-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav"> <d:prop> <c:calendar-data /> </d:prop> <c:filter> <c:comp-filter name="VCALENDAR"> <C:comp-filter name="VEVENT"> <C:time-range start="20131115T000000Z" end="20131201T000000Z"/> </C:comp-filter> </c:comp-filter> </c:filter> </c:calendar-query>:-)
这篇关于使用PHP / CalDAV读取Apple / iCloud日历数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!