【发布时间】:2016-01-26 10:59:27
【问题描述】:
我正在尝试将我的应用程序(Windows 桌面应用程序和 Web 应用程序)与移动日历集成。
我的应用程序应该是
- 将新事件推送到移动日历
- 从移动日历中获取事件
到目前为止,我设法与 Google 日历集成(非常简单,simple library + OAuth)
现在我想对 iCloud 日历做同样的事情,但这并不容易。
- 在 iCould 设置中,我可以公开日历。我可以获取事件(作为 iCalendar 文件),但我无法推送事件。
- 找不到任何用于 iCould 日历集成的重要库。我尝试了CalDav.Client,但需要提供 CalDAV 服务器 url。根据this 应该看起来像“
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 错误请求
【问题讨论】:
-
什么是“您的应用程序”?它是一个iOS应用程序吗?还是网络服务?
-
@hnh 这是一个 Windows 桌面应用程序,或者是一个 Web 应用程序(最好是桌面,但 Web 也可以)。
-
编辑 2:很可能 URL 是错误的。仔细(重新)阅读Building a CalDAV Client。
-
@gisek,你写了一个成功连接icloud日历的代码吗?
-
@Beetlejuice 不,但老实说我很快就放弃了
标签: c# ios iphone calendar caldav