php源码icloud,通过PHP的iCloud CalDAV
我正在嘗試編寫基本的CalDAV交互腳本,以便與Apple的給定帳戶的iCloud日歷一起使用.目前,我收到的回復如下:
Precondition Failed
Requested resource has a matching ETag.
$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);
?>
有誰知道響應意味著什么,或者如何解決它?我意識到腳本是非?;镜?但我希望在將它整理成一個類之前先得到一些工作.
提前感謝您的任何建議/幫助.
解決方法:
當然,在花費數小時解決問題并訴諸SO之后,你的大腦就開始了.
我錯過了$uid var,需要設置為唯一(或現有更新)事件ID.以下應該適用于任何試圖實現相同目標的人:
$account = array(
'server'=> 'p05',
'id' => '######',
'user' => 'a****z@me.com',
'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);
?>
我的錯.
標簽:php,curl,calendar,icloud,caldav
來源: https://codeday.me/bug/20190625/1286352.html
總結
以上是生活随笔為你收集整理的php源码icloud,通过PHP的iCloud CalDAV的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 计算机管理3d设置在哪,nvidia控制
- 下一篇: 基于Flickr的图片搜索