Here’s some simple PHP code, to get google gmail contacts.
File: getcontacts.php
<?php
if(!isset($_GET["code"]))
header("location: https://accounts.google.com/o/oauth2/auth?client_id=enteryourclientidhere&redirect_uri=http://yoursite.com/getcontacts.php&scope=https://www.google.com/m8/feeds/&response_type=code");
$authcode= $_GET["code"];
$clientid='enteryourclientidhere';
$clientsecret='enteryourclientsecrethere';
$redirecturi='http://yoursite.com/getcontacts.php';
$fields=array(
'code'=> urlencode($authcode),
'client_id'=> urlencode($clientid),
'client_secret'=> urlencode($clientsecret),
'redirect_uri'=> urlencode($redirecturi),
'grant_type'=> urlencode('authorization_code')
);
//url-ify the data for the POST
$fields_string='';
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
$fields_string=rtrim($fields_string,'&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,'https://accounts.google.com/o/oauth2/token');
curl_setopt($ch,CURLOPT_POST,5);
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
// Set so curl_exec returns the result instead of outputting it.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//to trust any ssl certificates
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);
//extracting access_token from response string
$response= json_decode($result);
$accesstoken= $response->access_token;
//passing accesstoken to obtain contact details
$xmlresponse= file_get_contents('https://www.google.com/m8/feeds/contacts/default/full?max-results=9999&oauth_token='.$accesstoken);
//echo $xmlresponse;
//reading xml using SimpleXML
$xml= new SimpleXMLElement($xmlresponse);
$xml->registerXPathNamespace('gd', 'http://schemas.google.com/g/2005');
$xml->registerXPathNamespace('default', 'http://www.w3.org/2005/Atom');
$result = $xml->xpath('//default:entry|//gd:email');
for($i=0;$i if(isset($result[$i+1]->attributes()->address)) "; } ?>
echo $result[$i]->title .":". $result[$i+1]->attributes()->address . "