【问题标题】:Google Contacts API v3 - How to Fetch contacts with email id?Google Contacts API v3 - 如何使用电子邮件 ID 获取联系人?
【发布时间】:2015-02-02 11:43:13
【问题描述】:

有没有办法通过电子邮件 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');

但我如何才能将电子邮件详细信息与相应的联系方式相匹配?

【问题讨论】:

标签: php email google-oauth google-contacts-api


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-12
    • 2016-01-19
    • 1970-01-01
    • 2013-09-25
    相关资源
    最近更新 更多