我试图脚本与给定帐户的苹果iCloud的日历使用基本的CalDAV互动。 目前,我收到如下所示的响应:
Precondition Failed
Requested resource has a matching ETag.
我正在使用的代码最初是取自http://trentrichardson.com/2012/06/22/put-caldav-events-to-calendar-in-php/并适合于以下:
<?php
$account = array(
'server'=> 'p05',
'id' => '######',
'user' => 'a****z@me.com',
'pass' => '*****'
);
$url = 'https://'.$account['server'].'-caldav.icloud.com/'.$account['id'].'/calendars/work/';
$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: *', //Possibly this line causing a problem - unsure of what it does?
'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);
$res = curl_exec($ch);
curl_close($ch);
print_r($res);
?>
你可以从这个脚本抓住你的用户ID: https://github.com/muhlba91/icloud/blob/master/PHP/icloud.php
没有人有任何想法响应意味着什么,或者如何解决呢? 我知道剧本是非常基本的,但我想整理成一个类之前得到的东西的工作。
预先感谢任何建议/帮助。