email - Issue with Importing gmail contact list from Oauth and php -


i trying import gmail contact list of registered users.

my index.php this-

<html> <head>     <meta name="robots" content="noindex" />     <title>import gmail or google contacts</title> <style type="text/css">     a:link {color:chocolate;text-decoration: none;}     a:hover {color:cornflowerblue;}     .logo{width:100%;height:110px;border:2px solid black;background-color:#666666;} </style> </head> <body>  <br/>     <div align="center" >         <a  style="font-size:25px;font-weight:bold;" href="https://accounts.google.com/o/oauth2/auth?client_id=969153863001-sfc4igc17cgqjqoifafqmjjbr6bouha3.apps.googleusercontent.com&redirect_uri=http://localhost/import_gmail/oauth.php&scope=https://www.google.com/m8/feeds/&response_type=code">click here import gmail contacts</a>     </div> </body> 

and oauth.php -

<?php $client_id = '969153863001-sfc4igc17coifafqmjjbr6bouha3.apps.googleusercontent.com'; $client_secret = 'tcmnd2umbguesglopgwcoojh2bnl'; $redirect_uri = 'http://wwww.mysite.com/import_gmail_contacts/oauth.php'; $max_results = 100;  $auth_code = $_get["code"];  function curl_file_get_contents($url) {  $curl = curl_init();  $useragent = 'mozilla/4.0 (compatible; msie 6.0; windows nt 5.1; .net clr 1.1.4322)';   curl_setopt($curl,curlopt_url,$url);     curl_setopt($curl,curlopt_returntransfer,true);      curl_setopt($curl,curlopt_connecttimeout,5);      curl_setopt($curl, curlopt_useragent, $useragent);   curl_setopt($curl, curlopt_followlocation, true);    curl_setopt($curl, curlopt_autoreferer, true);   curl_setopt($curl, curlopt_timeout, 10);     curl_setopt($curl, curlopt_ssl_verifypeer, 0);   curl_setopt($curl, curlopt_ssl_verifyhost, 0);   $contents = curl_exec($curl);  curl_close($curl);  return $contents;  }   $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 $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?max-   results='.$max_results.'&oauth_token='.$accesstoken;  $xmlresponse =  curl_file_get_contents($url);  if((strlen(stristr($xmlresponse,'authorization required'))>0) &&   (strlen(stristr($xmlresponse,'error '))>0)) { echo "<h2>oops !! went wrong. please try reloading page.</h2>"; exit();  } 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 $title) {   echo $title->attributes()->address . "<br>";   }   ?> 

now problem is, enable import contact list particular user has logged in. importing contact lists of e-mail id logged in browser e-mail id.

so, how update code can explicitly fetch contact list desire.

thanks

i think url must :

$url = 'https://www.google.com/m8/feeds/contacts/{otherusersemail}/full?max-   results='.$max_results.'&oauth_token='.$accesstoken 

rather

$url = 'https://www.google.com/m8/feeds/contacts/default/full?max-   results='.$max_results.'&oauth_token='.$accesstoken 

because if it's default, api use email of client_id owner : you.

don't forget edit : {otherusersemail} ... other user's email address.

reference : https://developers.google.com/google-apps/contacts/v3/?csw=1#retrieving_all_contacts


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -