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

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (274)

我试图用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?

提问于
用户回答回答于

如果使用HTTPPUT请求,你的意图是取代正在引用的uri中的资源。所以示例HTTP请求告诉我替代:

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

这是对的吗?可能希望在该集合中创建新的日历资源。因此,为你的资源选择一个新的url,它还不存在:

https://cloud.org/remote.php/dav/calendars/mycalendars/activity/foo-bar-baz.ics

扫码关注云+社区

领取腾讯云代金券