使用PHP将事件添加到贝加尔湖CalDAV服务器 [英] Adding events to Baikal CalDAV server using PHP

查看:120
本文介绍了使用PHP将事件添加到贝加尔湖CalDAV服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将事件推送到Webhost上安装的CalDAV日历。我正在使用贝加尔湖 CalDAV服务器。

I want to push events to a CalDAV calendar that is installed on my webhost. I am using the Baikal CalDAV server.

这是我的PHP:

<?php
    $uid = "test-12345"; // setting this to an existing uid updates event, a new uid adds event
    $url = "http://infobo9.myhostpoint.ch/dav/cal.php/principals/bookify"; //http://mail.domain.com/calendars/DOMAIN/USER/Calendar/'.$uid.'.ics'
    $userpwd = "bookify:test";
    $description = 'My event description here';
    $summary = 'My event title 1';
    $tstart = '20141127T000000Z';
    $tend = '20141127T000000Z';
    $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";

    echo $body . "<br>";

    $headers = array(
        'Content-Type: text/calendar; charset=utf-8',
        'If-None-Match: *',
        'Expect: ',
        'Content-Length: '.strlen($body),
    );
       $fp = fopen(dirname(__FILE__).'/errorlog.txt', 'w');

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_STDERR, $fp);
    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);

    echo "done"
?>

PHP输出:

<<<__EOD BEGIN:VCALENDAR VERSION:2.0 BEGIN:VEVENT DTSTAMP:20141127T181856Z DTSTART:20141127T000000Z DTEND:20141127T000000Z UID:test-12345 DESCRIPTION:My event description here LOCATION:Office SUMMARY:My event title 1 END:VEVENT END:VCALENDAR __EOD
done

我将其作为CURL输出:

I get this as CURL output:

* About to connect() to infobo9.myhostpoint.ch port 80 (#0)
*   Trying 217.26.52.30... * connected
* Connected to infobo9.myhostpoint.ch (217.26.52.30) port 80 (#0)
* Server auth using Basic with user 'bookify'
> PUT /dav/cal.php/principals/bookify HTTP/1.1
Host: infobo9.myhostpoint.ch
Accept: */*
Content-Type: text/calendar; charset=utf-8
If-None-Match: *
Content-Length: 260

< HTTP/1.1 200 OK
< Date: Thu, 27 Nov 2014 18:02:16 GMT
< Server: Apache/2.2.29 (FreeBSD) DAV/2 mod_ssl/2.2.29 OpenSSL/1.0.1j mod_hcgi/0.9.4
< X-Powered-By: PHP/5.4.32
< Set-Cookie: PHPSESSID=j2q0hmd7tvvo2egbf521tj5q82; path=/; HttpOnly
< Expires: Thu, 19 Nov 1981 08:52:00 GMT
< Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
< Pragma: no-cache
< Transfer-Encoding: chunked
< Content-Type: text/html
< 
* Connection #0 to host infobo9.myhostpoint.ch left intact
* Closing connection #0

该事件未添加到CalDAV服务器。知道为什么这行不通吗?

The event is not being added to the CalDAV server. Any idea why this does not work?

推荐答案

问题是URL不正确。正确的网址是:

The problem was that the URL was not correct. The correct URL is:

http://<domain>/dav/cal.php/calendars/<username>/<calendar-name>/<event-id>.ics

这篇关于使用PHP将事件添加到贝加尔湖CalDAV服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆