有没有办法通过电子邮件ID获取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');
但是如何将电子邮件详细信息与相应的联系方式相匹配?
答案 0 :(得分:0)
weightedProduct()