Glitch Alpha
New Member
I am using PHP. I want to fetch all gmail contacts of a user, i am using a PHP code that is calling google API through CURL. But, when i am doing this on localhost, it is doing well and giving me all contacts.But when i am doing this on online server that server in US, it is giving me response "Account Disabled" and also receiving a security mail by same user from google.i am using below code :\[code\]function getGmailContacts($user, $password) {//========================================== step 1: login ===========================================================$login_url = "https://www.google.com/accounts/ClientLogin";$fields = array( 'Email' => $user, 'Passwd' => $password, 'service' => 'cp', // <== contact list service code 'source' => 'test-google-contact-grabber', 'accountType' => 'GOOGLE',);$curl = curl_init();curl_setopt($curl, CURLOPT_URL,$login_url);curl_setopt($curl, CURLOPT_POST, 1);curl_setopt($curl, CURLOPT_POSTFIELDS,$fields);curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($curl);$returns = array();foreach (explode("\n",$result) as $line){ $line = trim($line); if (!$line) continue; list($k,$v) = explode("=",$line,2); $returns[$k] = $v;}curl_close($curl);//echo "<pre>"; //print_r($returns);exit;if(!isset($returns['Error'])) { //========================== step 2: grab the contact list =========================================================== $feed_url = "http://www.google.com/m8/feeds/contacts/$user/full?alt=json&max-results=250"; $header = array( 'Authorization: GoogleLogin auth=' . $returns['Auth'], ); $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $feed_url); curl_setopt($curl, CURLOPT_HTTPHEADER, $header); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); $result = curl_exec($curl); curl_close($curl); $data = http://stackoverflow.com/questions/10551568/json_decode($result, true); //echo"<pre>"; //print_r($data);exit; $contacts = array(); $i=0; foreach ($data['feed']['entry'] as $entry) { //echo $i." "; $entryElement = $entry; if(isset($entryElement['gd$email'])) { $gdEmailData = http://stackoverflow.com/questions/10551568/$entryElement['gd$email'][0]; //$contact->title = $entryElement['title']['$t']; //$contact->email = $gdEmailData['address']; $contacts[$gdEmailData['address']] = $entryElement['title']['$t']; } } //var_dump($contacts); //print_r($contacts); return $contacts;}else { if($returns['Error']=='BadAuthentication') { //echo '<strong>User Name and Password is incorrect.</strong>'; $errorArr = array("Error"=>"User Name and Password is incorrect."); //print_r($errorArr); return $errorArr; }}\[/code\]}That mail contains that \[quote\] "Someone recently tried to use an application to sign in to your Google Account....Location: New York NY, New York, United States....."\[/quote\].I thing this error is occurring from location change.can any one help me please? Thanks in advance.