dpqg86714 2018-06-04 21:54
浏览 182
已采纳

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

I'm trying to create a calendar event in Nextcloud with PHP and cURL. After running the code from command line, I get the following error from Nextcloud 12:

PUT is not allowed on non-files.

Here is the full code I'm using following 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;
?>

Does this mean that CalDAV in Nextcloud doesn't support PUT? So how do calendar applications like Thunderbird Lightning create events in Nextcloud?

In the Nextcloud WebDAV documentation I can't find anything about CalDAV implementation.

  • 写回答

1条回答 默认 最新

  • dqdt45183 2018-06-04 21:57
    关注

    If you use a HTTP PUT request, the intention is that you replace the resource at the uri that you are referencing. So your sample HTTP request is telling me that you are replacing:

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

    Is that correct? Probably not! You probably want to create a new calendar resource in that collection. So pick a new url for your resource that doesn't exist yet:

    https://cloud.org/remote.php/dav/calendars/mycalendars/activity/foo-bar-baz.ics
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题