我正在尝试编写基本的 CalDAV 交互脚本,以便与给定帐户的 Apple iCloud 日历一起使用。目前,我收到如下所示的回复:
Precondition Failed
Requested resource has a matching ETag.
Run Code Online (Sandbox Code Playgroud)
我使用的代码最初取自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 …Run Code Online (Sandbox Code Playgroud)