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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 统信uos升级apt后启动失败
  • ¥15 求指导储层饱和度及含水率测井解释
  • ¥200 建三维地震工区写入sgy到指定目录
  • ¥30 靶向捕获测序探针设计自学
  • ¥15 写代码写代码单片机代码写代码写数字按键代码
  • ¥15 django按照距离进行排序
  • ¥15 (标签-微信|关键词-微信公众号)
  • ¥15 matlab中mjs用不了
  • ¥15 Ios抖音直播的时候如何添加自定义图片在直播间!
  • ¥60 riscv-pulpino总线上挂载axi从机