[英]Google Contacts API v3 - How to Fetch contacts with email id?
Is there a way to fetch Google contacts(Google Contacts API v3) with email id? 有没有一种方法可以通过电子邮件ID提取Google联系人(Google Contacts API v3)?
What I have done so far is : 到目前为止,我所做的是:
$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>";
}
To fetch email details I used: 要获取我使用的电子邮件详细信息,请执行以下操作:
$result = $xml->xpath('//gd:email');
But how can I match email details with respective contact details? 但是,如何将电子邮件详细信息与各自的联系详细信息进行匹配?
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.