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);
正如Angelo所說,您需要提供錯誤信息。你有401嗎?也許該帳戶使用兩個身份驗證,你需要提供應用程序特定的密碼? – hnh