Update icloud calendar via php curl
I want to realize a script for managing events to a shared icloud
calendar. I've stored on my db several events and, on request, i need to
create an event to be seen on remote phones/ipad and so on.
Thanks to Andy and his post I had no problem for write an event to icloud,
but when I try to update or delete an event, icloud doesn't seem to record
any change. Below you can find part of the function I use to create the
event
$body = <<<__EOD
BEGIN:VCALENDAR
PRODID:-// blablabla
VERSION:2.0
BEGIN:VEVENT
METHOD:UPDATE
UID:$id
DTSTAMP:$tstamp
ORGANIZER;CN=$organizer:MAILTO:$email
DTSTART:$tstart
DTEND:$tend
SUMMARY:$name
LOCATION:$location
DESCRIPTION:$description
SEQUENCE:2
END:VEVENT
END:VCALENDAR
__EOD;
$headers = array(
'Content-Type: text/calendar; charset=utf-8',
'If-None-Match: *',
'Expect: ',
'Content-Length: '.strlen($body),
);
// CONNESSIONE E SCRITTURA
$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);
if(curl_errno($ch)) echo 'Curl error: '.curl_error($ch);
curl_close($ch);
If I exclude the connection to the icloud server and print $body the .ics
generated update without any problem my local calendar (and then replicate
the changes to icloud). Otherwise if I try to connect to icloud it won't
save the changes. I've tried to change the server request but still can't
get out of it
No comments:
Post a Comment