使用PHP在NextCloud中创建日历事件

我正在尝试使用PHP和cURL在Nextcloud中创建日历事件.从命令行运行代码后,我从Nextcloud 12收到以下错误:

PUT is not allowed on non-files.

这是我在this guide之后使用的完整代码

<?php
$url = 'https://cloud.org/remote.php/dav/calendars/mycalendars/activity/';
$headers = array('Content-Type: text/calendar', 'charset=utf-8');
$userpwd = 'gerald:123';
$description = 'new event description';
$summary = 'new event';
$tstart = gmdate("Ymd\THis\Z", strtotime("-2 days"));
$tend = gmdate("Ymd\THis\Z", strtotime("-2 days"));
$tstamp = gmdate("Ymd\THis\Z");
$uid = 'event-123';

$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;

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, $userpwd);
//curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);

//Execute the request.
$response = curl_exec($ch);
curl_close($ch);

echo $response;
?>

这是否意味着Nextcloud中的CalDAV不支持PUT?那么像Thunderbird Lightning这样的日历应用程序如何在Nextcloud中创建事件?

在Nextcloud WebDAV documentation中,我找不到任何有关CalDAV实现的信息.

解决方法:

如果您使用HTTP PUT请求,则意图是替换您引用的URI上的资源.所以你的示例HTTP请求告诉我你正在替换:

https://cloud.org/remote.php/dav/calendars/mycalendars/activity

那是对的吗?可能不是!您可能希望在该集合中创建新的日历资源.因此,为您尚未存在的资源选择一个新网址:

https://cloud.org/remote.php/dav/calendars/mycalendars/activity/foo-bar-baz.ics
上一篇:Ubuntu下手动安装NextCloud


下一篇:Docker安装NextCloud