2015-07-04 34 views
0

对于我而言,我无法将这些事件更新到iCloud。iCloud使用CURL更新的CalDAV

下面的cURL方法在iCloud中仍然有效吗?

我似乎无法看到它是连接到iCloud还是出现错误。

$account = array(
    'server'=> 'p05', 
    'id' => '######', 
    'user' => 'a****[email protected]', 
    'pass' => '*****' 
); 

$uid = 'event-12345'; 
$url = 'https://'.$account['server'].'-caldav.icloud.com/'.$account['id'].'/calendars/work/' . $uid . '.ics'; 
$userpwd = $account['user'] .":". $account['pass']; 
$description = 'Test event description'; 
$summary = 'Test event'; 
$tstart = gmdate("Ymd\THis\Z", strtotime("-2 days")); 
$tend = gmdate("Ymd\THis\Z", strtotime("-2 days")); 
$tstamp = gmdate("Ymd\THis\Z"); 

$body = <<<__EOD 
BEGIN:VCALENDAR 
VERSION:2.0 
BEGIN:VEVENT 
DTSTAMP:$tstamp 
DTSTART:$tstart 
DTEND:$tend 
UID:$uid 
DESCRIPTION:$description 
LOCATION:Office 
SUMMARY:$summary 
END:VEVENT 
END:VCALENDAR 
__EOD; 

$headers = array(
    'Content-Type: text/calendar; charset=utf-8', 
    'If-None-Match: *', 
    'Expect: ', 
    'Content-Length: '.strlen($body), 
); 

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 
curl_setopt($ch, CURLOPT_USERPWD, $userpwd); 
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $body); 
curl_exec($ch); 
curl_close($ch); 
+0

正如Angelo所说,您需要提供错误信息。你有401吗?也许该帐户使用两个身份验证,你需要提供应用程序特定的密码? – hnh

回答

0

你可以卷曲设置为详细模式,它会吐出大量的输出:

curl_setopt($ch, CURLOPT_VERBOSE, 1);

或者我可以建议你这样做? :

$response = curl_exec($ch); 
$info = curl_getinfo($ch); 
curl_close($ch); 

var_dump($response, $info); 

如果出现错误,应该将其显示在一些吐出的信息中。