drhwb470572 2014-11-26 11:57
浏览 96

阅读自由忙碌的calDAV iCloud PHP

I'm trying to read free-busy information from an iCloud calendar.

I based my solution on this php client https://github.com/muhlba91/icloud/blob/master/PHP/icloud.php

What works so far: Getting the Apple user number from an apple ID, using the credentials, this is needed to access the calDAV URL

Getting a list of the available calendars from a user (eg. Home, Work, ...)

What's not working: I cannot get a valid response from the Apple calDAV server.

The request (EDITED):

$ctag_request="<A:propfind xmlns:A='DAV:' xmlns:cs='https://p01-caldav.icloud.com/**USERID**/calendars/home/'>
    <A:prop>
       <cs:getctag />
    </A:prop>
</A:propfind>";


    $response=simplexml_load_string($this->doPropfindRequest($user['appleID'], $user['applepass'], $url, $ctag_request));

This is the DoRequest function. This is exactly the same as the propfind function i'm using to get the userID & list of calendars, except for the CURLOPT_CUSTOMREQUEST which is set to PROPFIND or REPORT. I conclude that the cURL part of my solution is correctly built.

function doReportRequest($user, $pw, $url, $xml)
{
    //Init cURL
    $c=curl_init($url);
    //Set headers
    curl_setopt($c, CURLOPT_HTTPHEADER, array("Depth: 1", "Content-Type: text/xml; charset='UTF-8'", "User-Agent: DAVKit/4.0.1 (730); CalendarStore/4.0.1 (973); iCal/4.0.1 (1374); Mac OS X/10.6.2 (10C540)"));
    curl_setopt($c, CURLOPT_HEADER, 0);
    //Set SSL
    curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($c, CURLOPT_SSL_VERIFYPEER, 0);
    //Set HTTP Auth
    curl_setopt($c, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($c, CURLOPT_USERPWD, $user.":".$pw);
    //Set request and XML
    curl_setopt($c, CURLOPT_CUSTOMREQUEST, 'PROPFIND');
    curl_setopt($c, CURLOPT_POSTFIELDS, $xml);
    curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
    //Execute
    $data=curl_exec($c);
    //Close cURL
    curl_close($c);

    return $data;
}

However, what apple returns me on this request is the following:

object(SimpleXMLElement)#259 (1) {
  ["response"]=>
  object(SimpleXMLElement)#261 (2) {
    ["href"]=>
     string(27) "/8126574070/calendars/home/"
     ["propstat"]=>
     object(SimpleXMLElement)#262 (2) {
      ["prop"]=>
      object(SimpleXMLElement)#260 (1) {
        ["getctag"]=>
        object(SimpleXMLElement)#263 (0) {
        }
      }
      ["status"]=>
      string(22) "HTTP/1.1 404 Not Found"
    }
  }
}

I get a 404 response. I think the problem is that the url is wrong. However i can't find anywhere online what the correct apple caldav URL is.

I'm hoping there is some calDAV expert that can help me on this issue.

EDIT

Allright, i edited the code/question since free-busy isn't supported by Apple and it's semi working.

  • 写回答

1条回答 默认 最新

  • dongyixiu3110 2014-11-28 15:20
    关注

    The supported-report precondition on the REPORT method is documented over here: http://www.webdav.org/specs/rfc3253.html#rfc.iref.d.17

    It simply means that this iCloud calendar does not support freebusy queries. You can see the same in the OS X calendar app if you create an event and open the availability panel. It says 'this calendar does not support availability' ...

    To extend the answer to the edited question: This is wrong:

    $ctag_request="<A:propfind xmlns:A='DAV:' xmlns:cs='https://p01-caldav.icloud.com/**USERID**/calendars/home/'>
      <A:prop>
        <cs:getctag />
      </A:prop>
    </A:propfind>";
    

    The namespace of the getctag property is "http://calendarserver.org/ns/". Try this:

    $ctag_request="<propfind xmlns='DAV:'>
      <prop>
        <getctag xmlns='http://calendarserver.org/ns/' />
      </prop>
    </propfind>";
    

    The https://p01-caldav.icloud.com/USERID/calendars/home/ is the URL of a calendar collection. It is not an XML namespace.

    And yes, if you get a 404, your URL is wrong / doesn't exist.

    Another issue might be that your authentication credentials are wrong. Are you providing an application password in your basic auth?

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度