我正在尝试将我的应用程序(Windows桌面应用程序和Web应用程序)与移动日历集成。
我的应用程序应该:
- 向移动日历推送新事件
- 从移动日历获取事件
到目前为止,我已经成功地与Google日历集成(非常容易,使用简单库 + OAuth)。
现在我想用iCloud日历做同样的事情,但这并不容易。
- 在iCloud设置中,我可以将日历设为公共。 然后我可以获取事件(作为iCalendar文件),但无法推送事件。
- 找不到任何认真的iCloud日历集成库。 我尝试过CalDav.Client,但需要提供CalDAV服务器网址,根据此文献,应该长这样"
https://pXX-caldav.icloud.com/USER_ID/calendars/CALENDAR_ID
"。 我不知道USER_ID
和CALENDAR_ID
是什么,也不知道在哪里找到它们。
有什么想法吗?
PS
有一个变通方法。 我可以要求用户创建一个Google帐户以及一个日历,并将其用作代理。 将iPhone与Google日历集成,然后从另一侧将我的应用程序与Google日历集成。 它有效,但对于用户来说配置有点繁琐。
编辑
我尝试了@hnh的指示,通过以下方式发现了CalDAV:
PROPFIND https://p42-caldav.icloud.com/ HTTP/1.1
Depth: 0
Prefer: return-minimal
Content-Type: application/xml; charset=utf-8
Host: p42-caldav.icloud.com
Content-Length: 102
<d:propfind xmlns:d="DAV:">
<d:prop>
<d:current-user-principal />
</d:prop>
</d:propfind>
结果是401:
HTTP/1.1 401 Unauthorized
Content-Type: text/html;charset=utf-8
WWW-Authenticate: x-mobileme-authtoken realm="MMCalDav"
WWW-Authenticate: basic realm="MMCalDav"
Server: iCloudCalendarServer 15G33
Date: Tue, 26 Jan 2016 12:46:14 GMT
X-Responding-Server: mr26p42ic-ztdg05101801 17 a63660a6f7d1a25b5a7ed66dab0da843
X-Transaction-Id: c8dc19d4-c42a-11e5-8381-008cfaeb448c
Content-Length: 141
Strict-Transport-Security: max-age=31536000; includeSubDomains
<html><head><title>Unauthorized</title></head><body><h1>Unauthorized</h1><p>You are not authorized to access this resource.</p></body></html>
编辑 2
按照进一步的说明,我成功进行了身份验证,但仍然在文章中的请求方面遇到问题:
对于:
<d:propfind xmlns:d="DAV:" xmlns:cs="http://calendarserver.org/ns/">
<d:prop>
<d:displayname />
<cs:getctag />
</d:prop>
</d:propfind>
我得到的是:(未找到
ctag
,并且displayName
的值为“tmp”-我不认识)<?xml version='1.0' encoding='UTF-8'?>
<multistatus xmlns='DAV:'>
<response>
<href>/</href>
<propstat>
<prop>
<displayname>tmp</displayname>
</prop>
<status>HTTP/1.1 200 OK</status>
</propstat>
<propstat>
<prop>
<getctag xmlns='http://calendarserver.org/ns/'/>
</prop>
<status>HTTP/1.1 404 Not Found</status>
</propstat>
</response>
</multistatus>
而对于这个:
<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:filter>
</c:calendar-query>
我收到了400错误请求。