1

I'm trying to do a CalDAV XML request to the google caldav server with PHP.

For some reason the google calDAV is very poorly documented.

The purpose is to get a list of all events, including the event-specific data. (eg. Begin, End, Summary, ...). The goal is to do this as efficiently as possible.(all event data in one request).

I figured out that this can be accomplished by a REPORT request.

I'm using code found in this post.

My exact code :

    $xml= '<c:calendar-query xmlns:d="DAV:" xmlns:c="urn:ietf:params:xml:ns:caldav"><d:prop><c:calendar-data /></d:prop></c:calendar-query>';
    $url = "https://apidata.googleusercontent.com/caldav/v2/*email*/events";
    $user = "**********@gmail.com";
    $pw = "*********";

    $data = $this->doRequest($user, $pw, $url, $xml);
    print_r($data);

}

public function doRequest($user, $pw, $url, $xml)
{
    $c=curl_init();
    $url = preg_replace('{^https?://[^/]+}', '', $url);
    curl_setopt($c, CURLOPT_URL, $url);
    curl_setopt($c, CURLOPT_HTTPHEADER, array("Depth: 1", "Content-Type: text/xml; charset='UTF-8'", "Prefer: return-minimal"));
    curl_setopt($c, CURLOPT_HEADER, 0);
    curl_setopt($c, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($c, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($c, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($c, CURLOPT_USERPWD, $user.":".$pw);
    curl_setopt($c, CURLOPT_CUSTOMREQUEST, "REPORT");
    curl_setopt($c, CURLOPT_POSTFIELDS, $xml);
    curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
    $data=curl_exec($c);

    curl_close($c);

    return $data;
}    

The xml request is copy-pasted from the SabreDAV wiki.

What google returns on this code is "Unknown Error". I know the credentials from the google are working, since i successfully tried some request using SabreDAV's built-in requests (eg. propfind). But a report request cannot be generated by SabreDAV.

So i think there must be something in the xml request that google caldav cannot handle properly.

I have been fiddling around with this for several days, but i can't seem to figure out a proper solution.

Community
  • 1
  • 1
Rbn
  • 13
  • 5
  • You need to find out more about that "Unkown Error" first. That message on it's own ist not asking much. Please make your programming question as concrete as possible first. – hakre Nov 05 '14 at 23:44
  • Random suggestion. Can you try removing the `Depth` header? I feel like I remember that that may have had something to do with it, but I'm not sure... – Evert Nov 06 '14 at 05:07
  • @hakre The question in short: what am i doing wrong to get a valid response from the google calDAV server? Research doesn't give me much on the "Unknown Error". – Rbn Nov 06 '14 at 09:34
  • @Rbn: That's what I could decipher from your posting already. However getting an error message alone does normally not qualify as a full question. You should always add what you've found out so far about the error message and how you did check if it applies to your scenario or not. Just in short. I know it might seem unmanageable to find out more (like standing in front of a wall no way through), but you need to at least give some more specifics. Also try to reduce the code in your scenario, that always helps. Explain each curl option you set and provide reference why you set it. Such things. – hakre Nov 06 '14 at 11:04

1 Answers1

0

Well, you seem to be using HTTP Basic Auth which is not allowed by the Google CalDAV API:

https://developers.google.com/google-apps/calendar/caldav/v2/guide#connecting_to_googles_caldav_server

Then, you did not specify which URL was the target of your request.

Arnaud Quillaud
  • 4,420
  • 1
  • 12
  • 8
  • I dropped the calDAV idea and used the Google Calendar API instead, which is using Oauth2. – Rbn Nov 26 '14 at 09:46