CardDAV-PHP
CardDAV-PHP copied to clipboard
Accessing google address book
Hi,
Have you been able to connect to google?
http://support.google.com/mail/bin/answer.py?hl=en&answer=2753077
tried
$carddav = new carddav_backend('https://google.com/'); $carddav->enable_debug(); $carddav->set_auth('[email protected]', 'password');
but fails.
I found another link (German) saying, that the google caldav url is: https://google.com/m8/carddav/principals/__uids__/YourName%40gmail.com/lists/default/ but I get another exception telling, that the server returned error #404.
I found the cause for my error #404. In line 299 the .vcf ending is appended, which shouldn't be there for google contacts. Maybe @graviox should add a parameter $ending or something like that.
maybe you could also use the content of the <d:href> tag which is included in the raw output and seams to contain the whole uri of the contact/vcard
i would also love support for google ;-)
@white-gecko i'm getting error 405 ... how did you solve this ?
removing the .vcf ending didn't work for me..
using the german url and removing .vcf just hangs...
Regarding to wikipedia error 405 is method not allowed, meaning something with GET/POST/… is wrong.
My diff for carddav.php is:
$ git diff carddav.php
diff --git a/carddav.php b/carddav.php
index ec76f65..ff4e9c6 100644
--- a/carddav.php
+++ b/carddav.php
@@ -296,7 +296,7 @@ class carddav_backend
public function get_vcard($vcard_id)
{
$vcard_id = str_replace('.vcf', null, $vcard_id);
- $result = $this->query($this->url . $vcard_id . '.vcf', 'GET');
+ $result = $this->query($this->url . $vcard_id, 'GET');
switch ($result['http_code'])
{
And I retrieve the contact data with following script:
<?php
require_once('carddav.php');
$carddav = new carddav_backend('https://google.com/m8/carddav/principals/__uids__/myname%40gmail.com/lists/default/');
$carddav->set_auth('[email protected]', 'mypassword');
$cards = $carddav->get(false);
$cardXml = new SimpleXMLElement($cards);
foreach ($cardXml->element as $element) {
echo $carddav->get_vcard($element->id);
}
I bumped into this issue as well... I don't think Google is doing anything wrong with their CardDAV setup, but it is certainly different to the other CardDAV servers I've been trying.
According to RFC 6352 (http://tools.ietf.org/html/rfc6352), "File names for vCards are commonly suffixed by ".vcf", and clients may choose to use the same convention for URLs." so .vcf is somewhat unclearly defined in that the RFC implies that both with and without the extension is acceptable.
I've committed what I hope is a good fix for the issue - essentially I've added the ability to set the extension to be used for the vcard queries, as well as a check to set_url that automatically configures it correctly when using Google.
See: https://github.com/jethrocarr/CardDAV-PHP/commit/2c3af2f2b8d2cb03f5145eb8531f24d6cbe196d5
Hello
I think google URL has been changed to
https://google.com/carddav/v1/principals/YourName%40gmail.com/
Hi @mrahmadt, It don't work with google, neither with this url. Now it returns a 200 response, with the url https://google.com/carddav/v1/principals/[email protected]/lists/default, but content and content_type are null, and the header returns string(1011) "HTTP/1.1 401 Unauthorized