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 用lstm来预测股票价格
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上