I'm trying to integrate my application (Windows desktop app, and Web app) with mobile calendars.
My application is supposed to
So far I managed to integrate with Google calendar (very easy, simple library + OAuth)
Now I want to do the same with iCloud calendar, but it's not that easy.
https://pXX-caldav.icloud.com/USER_ID/calendars/CALENDAR_ID
. I have no idea what USER_ID
and CALENDAR_ID
are and where to find them. Any ideas?
PS
There is a workaround. I can ask user to create a Google accout along with a calendar and use it as a proxy. Integrate IPhone with Google calendar and form the other site integrate my application with Google calendar. It works, but the configuration is kind of tedious for the user.
EDIT
I tried following @hnh's instructions and discover CalDAV this way:
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>
The result was 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>
EDIT 2
Following further instructions I managed to authenticate, but still have problems with the requests from the article:
For:
<d:propfind xmlns:d="DAV:" xmlns:cs="http://calendarserver.org/ns/">
<d:prop>
<d:displayname />
<cs:getctag />
</d:prop>
</d:propfind>
I get: (ctag
not found, and displayName
with value of "tmp" - which I don't recognize)
<?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>
And for this:
<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>
I get 400 Bad Request
This is a nice introduction: Building a CalDAV client. It also describes how the calendar discovery process works (how you find the calendar homeset URL).
Many CalDAV servers do not support OAuth, you'll usually have to ask the user for login/password.
There doesn't seem to be a .NET library for CalDAV. You can find a list of implementations over here: http://caldav.calconnect.org/implementations/librariestools.html.
Summary: Probably not as easy as what you did with Google, but not super hard either. And once you have it, you can connect to many different servers, given that CalDAV is a standard ... (including Google, you can connect to that with CalDAV as well).
Update after the EDIT of the question:
The 401 is a generic HTTP response. It means that you need to provide credentials to continue with the request. A client would usually prompt the user for login/password and then re-run the request. Basic authentication is well described in the Wikipedia article on Basic auth.
Another mistake is to use p42-caldav.icloud.com
as the entry point URL. Use caldav.icloud.com
as you don't know which partition the user is on. You need to use the discovery process as described in Building a CalDAV client to find the actual URL the users calendar is hosted on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With