CardDAV-PHP icon indicating copy to clipboard operation
CardDAV-PHP copied to clipboard

Accessing google address book

Open tttp opened this issue 13 years ago • 9 comments

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.

tttp avatar Oct 14 '12 15:10 tttp

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.

white-gecko avatar Dec 04 '12 21:12 white-gecko

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.

white-gecko avatar Dec 04 '12 21:12 white-gecko

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

white-gecko avatar Dec 04 '12 21:12 white-gecko

i would also love support for google ;-)

chellmann avatar Dec 12 '12 19:12 chellmann

@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...

pilosof avatar Dec 30 '12 07:12 pilosof

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);
}

white-gecko avatar Jan 02 '13 13:01 white-gecko

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

jethrocarr avatar Mar 07 '13 10:03 jethrocarr

Hello

I think google URL has been changed to

https://google.com/carddav/v1/principals/YourName%40gmail.com/

mrahmadt avatar Feb 25 '14 17:02 mrahmadt

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

clemenlg avatar Aug 18 '17 14:08 clemenlg