title: Google Contacts API v3 - How to Fetch contacts with email id?
body: <p>Is there a way to fetch Google contacts(Google Contacts API v3) with email id?</p>
  
  <p>What I have done so far is :</p>
  
  <pre><code>        $client_id=$this-&gt;config-&gt;item('google_access_key');
          $client_secret=$this-&gt;config-&gt;item('google_secret_key');
          $redirect_uri=$this-&gt;config-&gt;item('google_callback_url');
          $max_results = 9999;        
          $auth_code = $_GET["code"];
  
      $fields=array(
          'code'=&gt;  urlencode($auth_code),
          'client_id'=&gt;  urlencode($client_id),
          'client_secret'=&gt;  urlencode($client_secret),
          'redirect_uri'=&gt;  urlencode($redirect_uri),
          'grant_type'=&gt;  urlencode('authorization_code')
      );
      $post = '';
      foreach($fields as $key=&gt;$value) { $post .= $key.'='.$value.'&amp;'; }
      $post = rtrim($post,'&amp;');
  
      $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-&gt;access_token;
  
      $url = 'https://www.google.com/m8/feeds/contacts/default/full?oauth_token='.$accesstoken;
      $xmlresponse =  $this-&gt;curl_file_get_contents($url);
      if((strlen(stristr($xmlresponse,'Authorization required'))&gt;0) &amp;&amp; (strlen(stristr($xmlresponse,'Error '))&gt;0))
      {
          $msg = "OOPS !! Something went wrong. Please try reloading the page.";
          $newdata = array('msg'  =&gt; $msg);
          $this-&gt;session-&gt;set_userdata('message_session', $newdata);
          redirect('admin/social_account_master');
      }
      $xml =  new SimpleXMLElement($xmlresponse);
      $xml-&gt;registerXPathNamespace('gd', 'http://schemas.google.com/g/2005');
      foreach ($xml as $title) 
          {
              echo $title-&gt;title . "&lt;br&gt;";
          }
  </code></pre>
  
  <p>To fetch email details I used:</p>
  
  <pre><code>$result = $xml-&gt;xpath('//gd:email');
  </code></pre>
  
  <p>But how can I match email details with respective contact details?</p>