Raph L Raph L - 1 month ago 14
PHP Question

Getting <gd:name> instead of <title> in php google contact api

I tried different way to get the structured data of data like familyName or givenName... but I fail.

For example I tried to modify this code rapidwebltd/php-google-contacts-v3-api

Here is a sample:

$contactGDNodes = $xmlContactsEntry->children('http://schemas.google.com/g/2005');
foreach ($contactGDNodes as $key => $value) {
switch ($key) {
case 'organization':
$contactDetails[$key]['orgName'] = (string) $value->orgName;
$contactDetails[$key]['orgTitle'] = (string) $value->orgTitle;
break;
/* case 'name':
$contactDetails['sName']['familyName'] = (string) $value->familyName;
$contactDetails['sName']['givenName'] = (string) $value->givenName;
$contactDetails['sName']['fullName'] = (string) $value->fullName;
break;
case 'structuredPostalAddress':
$contactDetails[$key]['city'] = (string) $value->city;
break; */
case 'email':
$attributes = $value->attributes();
$emailadress = (string) $attributes['address'];
$emailtype = substr(strstr($attributes['rel'], '#'), 1);
$contactDetails[$key][$emailtype] = $emailadress;
break;


Data for 'organization' or 'email' work perfectly. In comment is the code I added which is "unseless" as the data are not available. Actually, with a var_dump of $contactGDNodes, I clearly see that the data I'm looking for are not present... do you have an idea what I'm missing ?

Thank you very much

Answer

A quick glance-through of the "v3" library you are using suggests that it is actually sending the request to version 1 of the API, not version 3. Add a v=3 to the URL parameter list to call the correct version that includes the name. If there is no name present in the raw XML response, then the contact itself has no name.

Comments