Google Contacts API v3 — Как получить контакты с идентификатором электронной почты?

Есть ли способ получить контакты Google (Google Contacts API v3) с идентификатором электронной почты?

Что я сделал до сих пор:

        $client_id=$this->config->item('google_access_key');
$client_secret=$this->config->item('google_secret_key');
$redirect_uri=$this->config->item('google_callback_url');
$max_results = 9999;
$auth_code = $_GET["code"];

$fields=array(
'code'=>  urlencode($auth_code),
'client_id'=>  urlencode($client_id),
'client_secret'=>  urlencode($client_secret),
'redirect_uri'=>  urlencode($redirect_uri),
'grant_type'=>  urlencode('authorization_code')
);
$post = '';
foreach($fields as $key=>$value) { $post .= $key.'='.$value.'&'; }
$post = rtrim($post,'&');

$curl = curl_init();
curl_setopt($curl,CURLOPT_URL,'https://accounts.google.com/o/oauth2/token');
curl_setopt($curl,CURLOPT_POST,5);
curl_setopt($curl,CURLOPT_POSTFIELDS,$post);
curl_setopt($curl, CURLOPT_RETURNTRANSFER,TRUE);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST,0);
$result = curl_exec($curl);
curl_close($curl);

$response =  json_decode($result);
$accesstoken = $response->access_token;

$url = 'https://www.google.com/m8/feeds/contacts/default/full?oauth_token='.$accesstoken;
$xmlresponse =  $this->curl_file_get_contents($url);
if((strlen(stristr($xmlresponse,'Authorization required'))>0) && (strlen(stristr($xmlresponse,'Error '))>0))
{
$msg = "OOPS !! Something went wrong. Please try reloading the page.";
$newdata = array('msg'  => $msg);
$this->session->set_userdata('message_session', $newdata);
redirect('admin/social_account_master');
}
$xml =  new SimpleXMLElement($xmlresponse);
$xml->registerXPathNamespace('gd', 'http://schemas.google.com/g/2005');
foreach ($xml as $title)
{
echo $title->title . "<br>";
}

Чтобы получить данные электронной почты, я использовал:

$result = $xml->xpath('//gd:email');

Но как я могу сопоставить данные электронной почты с соответствующими контактными данными?

1

Решение

echo "<h3>Email Addresses:</h3>";
$xml =  new SimpleXMLElement($xmlresponse);
$xml->registerXPathNamespace('gd', 'http://schemas.google.com/g/2005');
$result = $xml->xpath('//gd:email');

foreach ($result as $title) {
echo $title->attributes()->address . "<br>";
}
?>
i to used only email to retrive from google contacts how to retrive phone number and other detaisl
0

Другие решения

Других решений пока нет …