Updating Google Contacts with PHP

1,229 views
Skip to first unread message

peteyg

unread,
Aug 15, 2012, 5:48:30 AM8/15/12
to google-co...@googlegroups.com

I was wondering if anyone is aware of any code examples for updating Google Contacts data in PHP. I have no problems authenticating and retrieving contacts using Google's provided API (http://code.google.com/p/google-api-php-client/wiki/OAuth2)

However, this does not appear to have any support for manipulating the contacts. I have also tried Zend Gdata (http://framework.zend.com/download/gdata/) to achieve this, but this works off oAuth 1.0. Which is not only deprecated, but I cannot verify my URLs (as they are on an intranet).

The guide (https://developers.google.com/google-apps/contacts/v3/) is useful, but has no specific PHP examples. The main problem I'm having revolves around trying to send authenticated cURL requests.. This guide (https://developers.google.com/gdata/articles/using_cURL#updating-entries) has been useful but still I have found no solution so far.

Any help or suggestions would be greatly appreciated!

Message has been deleted

steki

unread,
Aug 18, 2012, 5:54:06 AM8/18/12
to google-co...@googlegroups.com
more information welcome, i am interessed too :-)

peteyg

unread,
Aug 24, 2012, 10:23:51 AM8/24/12
to google-co...@googlegroups.com
After creating the batch XML I used the following snippet, which is working really well:

$headers = array(
'Host: www.google.com',
'Content-length: '.strlen($contactXML),
'Content-type: application/atom+xml',
'Authorization: OAuth '.$integration['AuthToken'],
);


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $contactQuery );
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $contactXML);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
$response = curl_exec($ch);
if($response === false) {
$content .= 'cURL Operation Failed ('.curl_error($ch).')<br />';
} else {
$content .= 'cURL Operation Successful<br />';
}

curl_close($ch);

peteyg

unread,
Aug 24, 2012, 10:25:08 AM8/24/12
to google-co...@googlegroups.com
Also this page is really useful for testing:  https://developers.google.com/oauthplayground/ 


On Wednesday, 15 August 2012 10:48:30 UTC+1, peteyg wrote:
Reply all
Reply to author
Forward
0 new messages