php源码icloud,通过php的icloud caldav -凯发k8官方网
我正在尝试编写基本的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
总结
以上是凯发k8官方网为你收集整理的php源码icloud,通过php的icloud caldav的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇:
- 下一篇: