4

我试图通过 CalDAV 获取 iCloud 日历的日历事件来快速找到空闲/忙碌时间。我能够获取可用的日历,并且根据此处的文档或使用DAViCal 客户端库获取给定日期范围的日历信息应该像将此 REPORT xml 请求发送到日历 URL(即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>

这本质上就是GetEvents()函数在 DAViCal 库中的作用。但是,我只是在回复中获取每个日历条目的 URL,而不是日历数据本身:

<?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 请求,但显然这很慢。在一个请求中下载日历数据是否有技巧?

4

2 回答 2

4

如果你只包括它就可以了

<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="20131115T000000Z" end="20131201T000000Z"/>
          </C:comp-filter>
</c:comp-filter>
</c:filter>
</c:calendar-query>

:-)

于 2014-01-03T19:14:44.267 回答
0

现在,苹果日历服务器支持这两个标签。

我正在使用日历服务器 9.0。

<?xml version="1.0" encoding="utf-8" ?>
<C:calendar-query
    xmlns:D="DAV:"
    xmlns:C="urn:ietf:params:xml:ns:caldav">
    <D:prop>
        <D:getetag />
        <C:calendar-data>
            <C:comp name="VCALENDAR">
                <C:prop name="VERSION"/>
                <C:comp name="VEVENT"></C:comp>
            </C:comp>
            <C:expand start="20170101T060000Z" end="20170630T060000Z"/>
        </C:calendar-data>
    </D:prop>
    <C:filter>
        <C:comp-filter name="VCALENDAR">
            <C:comp-filter name="VEVENT">
                <C:time-range end="20170630T060000Z" start="20170101T060000Z"/>
            </C:comp-filter>
        </C:comp-filter>
    </C:filter>
</C:calendar-query>

回复 -

<?xml version='1.0' encoding='UTF-8'?>
<multistatus xmlns='DAV:'>
  <response>
    <href>/calendars/users/test/calendar/43fdddd1-ad3a-4c00-ac63-a76d89e074da.ics</href>
    <propstat>
      <prop>
        <getetag>"14db35d8d385ee62ced664efd56d3ac4"</getetag>
        <calendar-data xmlns='urn:ietf:params:xml:ns:caldav'><![CDATA[BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
UID:43fdddd1-ad3a-4c00-ac63-a76d89e074da
DTSTART;VALUE=DATE:20170110
DTEND;VALUE=DATE:20170111
CATEGORIES:Birthday
CREATED:20170130T070433Z
DESCRIPTION:Birthday from thunderbird
DTSTAMP:20170130T070515Z
LAST-MODIFIED:20170130T070515Z
SUMMARY:Test Event 123
TRANSP:TRANSPARENT
END:VEVENT
END:VCALENDAR
]]></calendar-data>
      </prop>
      <status>HTTP/1.1 200 OK</status>
    </propstat>
  </response>
  <response>
    <href>/calendars/users/test/calendar/53f7e764-9e46-4f7d-a851-714f9ea03ad1.ics</href>
    <propstat>
      <prop>
        <getetag>"e08f17f5f7483d31017c5391a7618d9b"</getetag>
        <calendar-data xmlns='urn:ietf:params:xml:ns:caldav'><![CDATA[BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
UID:53f7e764-9e46-4f7d-a851-714f9ea03ad1
DTSTART:20170112T093000Z
DTEND:20170112T103000Z
CREATED:20170130T092637Z
DESCRIPTION:Time based Event
DTSTAMP:20170130T092651Z
LAST-MODIFIED:20170130T092651Z
SUMMARY:Time based Event
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR
]]></calendar-data>
      </prop>
      <status>HTTP/1.1 200 OK</status>
    </propstat>
  </response>
  <response>
    <href>/calendars/users/test/calendar/73a21941-ac24-492a-b00e-48d38feb7d01.ics</href>
    <propstat>
      <prop>
        <getetag>"8bceb0306b81b67a8dfb2f5d95d76dd1"</getetag>
        <calendar-data xmlns='urn:ietf:params:xml:ns:caldav'><![CDATA[BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
UID:73a21941-ac24-492a-b00e-48d38feb7d01
DTSTART;VALUE=DATE:20170111
DTEND;VALUE=DATE:20170112
CATEGORIES:Favorites
CREATED:20170130T073845Z
DESCRIPTION:Duration Event Desc
DTSTAMP:20170130T092634Z
LAST-MODIFIED:20170130T092634Z
SEQUENCE:1
SUMMARY:Duration Event
TRANSP:TRANSPARENT
X-MOZ-GENERATION:1
END:VEVENT
END:VCALENDAR
]]></calendar-data>
      </prop>
      <status>HTTP/1.1 200 OK</status>
    </propstat>
  </response>
</multistatus>
于 2017-02-02T08:02:59.603 回答