How can I get calendar events with calDav from Nextcloud in php?

69 views Asked by At

I try to get access to my nextcloud calendar events via caldav in my php script:

    $calDavUrl = 'https://cloud.myproject.mywebsite.com/remote.php/dav/calendars/[email protected]/personal/';
    $username = '[email protected]';
    $password = 'mypassword';

    
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $calDavUrl);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PROPFIND');
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Depth: 1','Prefer:return-minimal'));


    $result = curl_exec($ch);

    $httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    echo 'HTTP Status: ' . $httpStatus . "\n<br>";
    var_dump($result);

My Calendar events are listed like this:

<d:response>
        <d:href>/remote.php/dav/calendars/[email protected]/personal/76F684E8-7438-40EE-A6CC-8A4E447E191A.ics</d:href>
        <d:propstat>
            <d:prop>
                <d:getlastmodified>Thu, 25 Jan 2024 11:24:59 GMT</d:getlastmodified>
                <d:getcontentlength>380</d:getcontentlength>
                <d:resourcetype/>
                <d:getetag>&quot;a040cf880e1b9d6ee5bffff3f9c35086&quot;</d:getetag>
                <d:getcontenttype>text/calendar; charset=utf-8; component=vevent</d:getcontenttype>
            </d:prop>
            <d:status>HTTP/1.1 200 OK</d:status>
        </d:propstat>
    </d:response>

But I need the c:calendar-data like this:

<d:response>
        <d:href>/remote.php/dav/calendars/[email protected]/personal/76F684E8-7438-40EE-A6CC-8A4E447E191A.ics</d:href>
        <d:propstat>
            <d:prop>
                <d:getetag>"2134-314"</d:getetag>
                <c:calendar-data>BEGIN:VCALENDAR
                    VERSION:2.0
                    CALSCALE:GREGORIAN
                    BEGIN:VTODO
                    UID:132456762153245
                    SUMMARY:Do the dishes
                    DUE:20121028T115600Z
                    END:VTODO
                    END:VCALENDAR
                </c:calendar-data>
            </d:prop>
            <d:status>HTTP/1.1 200 OK</d:status>
        </d:propstat>
    </d:response>

How can I get access to them?

0

There are 0 answers