Has anyone had experience using the Google Contacts API?

Hey all,

Using the Google Contacts API I want to check if a contact is in the “My Contacts” group, if not, add them. Has anyone already done this with PHP before? There doesn’t appear to be much on the subject :confused: Any help would be greatly appreciated, Thanks

The API looks fairly straightforward, how would you determine whether they are unique or not? Name? Email? Telephone number?

You would have to use the ‘Protocol’ API, which is just HTTP so you’re fine there. :slight_smile:

I am assuming this is just for 1 user? ie. You?

I found the following article on IBM, Integrate your PHP application with Google Contacts

You can use the supplied code in the article to create a check that looks for an email matching the input email. However to add a contact to a group I did the following.

Edit the code for Listing 10: Adding new contacts

Add the following to line 76:


$entry->setAttributeNS('http://www.w3.org/2000/xmlns/' ,'xmlns:gContact', 'http://schemas.google.com/contact/2008');

You must add that namespace for the next code to work.

And add the following after line 100:


//add to 'My Contacts' groups
$group = $doc->createElement('gContact:groupMembershipInfo');
$group->setAttribute('deleted' ,'false');
$group->setAttribute('href' ,'http://www.google.com/m8/feeds/groups/'.$user.'/base/6');
$entry->appendChild($group);

In the above code the $user variable is the accounts email, it’s already a variable used in the code. It can’t be “default”, that doesn’t work. The number on the end, in this case 6, is the number of the group you want to add the contact too. You can easily find this out in Gmail just by hovering over the link of the group.

I hope this saves someone some time, and please post this on the IBM article’s comments if you have an account.