[英]Create calendar events in NextCloud using PHP
我正在尝试使用PHP和cURL在Nextcloud中创建日历事件。 从命令行运行代码后,我从Nextcloud 12收到以下错误:
PUT is not allowed on non-files.
以下是我在本指南后使用的完整代码
<?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文档中,我找不到任何有关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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.