PHP Classes

Grab Gmail Contacts not working

Recommend this page to a friend!

      Contact Grabber  >  All threads  >  Grab Gmail Contacts not working  >  (Un) Subscribe thread alerts  
Subject:Grab Gmail Contacts not working
Summary:Grab Gmail Contacts not working
Messages:11
Author:Billy
Date:2008-05-07 22:29:30
Update:2010-02-02 05:05:28
 
  1 - 10   11 - 11  

  1. Grab Gmail Contacts not working   Reply   Report abuse  
Picture of Billy Billy - 2008-05-07 22:29:30
Hello Friends,

I'm trying to use this class to import Hotmail and Gmail contacts. The Hotmail importing is working perfectly, but the Gmail is not.

When I enter the Gmail username and password, it authenticates it, but then no contacts are retrieved.

Please let me know what the problem can be in fetching the contacts from Gmail.

Thanks so much.
-Billy

  2. Re: Grab Gmail Contacts not working   Reply   Report abuse  
Picture of jaja jaja - 2008-05-12 10:30:50 - In reply to message 1 from Billy
same problem here :(

  3. Re: Grab Gmail Contacts not working   Reply   Report abuse  
Picture of jaja jaja - 2008-05-12 10:33:31 - In reply to message 1 from Billy
check this: http://www.phpclasses.org/discuss/package/3895/thread/15/

  4. Re: Grab Gmail Contacts not working   Reply   Report abuse  
Picture of Stephan Stephan - 2008-09-05 04:49:22 - In reply to message 1 from Billy
I'm trying to use this class to import Hotmail and Gmail contacts. The Gmail importing is working perfectly, but the Hotmail is not. :'( help me please

  5. Re: Grab Gmail Contacts not working   Reply   Report abuse  
Picture of qunxyz qunxyz - 2009-01-16 02:18:21 - In reply to message 4 from Stephan
I had modify this library.My code is below here,but it could be smaller:
<?php
#Copyright 2006 Svetlozar Petrov
#All Rights Reserved
#svetlozar@svetlozar.net
#http://svetlozar.net

#Script to import the names and emails from gmail contact list


class GMailer extends baseFunction
{
var $location = "";
var $cookiearr = array();

#Globals Section, $location and $cookiearr should be used in any script that uses
#getAddressbook function
#function getAddressbook, accepts as arguments $login (the username) and $password
#returns array of: array of the names and array of the emails if login successful
#otherwise returns 1 if login is invalid and 2 if username or password was not specified

function getAddressbook($login, $password)

{
#the globals will be updated/used in the read_header function
global $location;
global $cookiearr;
global $ch;

#check if username and password was given:
if ((isset($login) && trim($login)=="") || (isset($password) && trim($password)==""))
{
return false;
}

#initialize the curl session
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://mail.google.com/mail");
curl_setopt($ch, CURLOPT_REFERER, "");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_COOKIESESSION, TRUE); # PHP5 only
curl_setopt ($ch, CURLOPT_POST, false);
curl_setopt ($ch, CURLOPT_COOKIEFILE, dirname(__FILE__)."/cookie.txt");
curl_setopt ($ch, CURLOPT_COOKIEJAR, dirname(__FILE__)."/cookie.txt");
//curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'read_header');
//curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this, 'read_header'));

#get the html from gmail.com
$html = curl_exec($ch);
$matches = array();
$actionarr = array();
//echo $html;die('here');
//echo htmlentities($html);die('here');
$action = "https://www.google.com/accounts/ServiceLoginAuth";

#parse the login form:
#parse all the hidden elements of the form
preg_match_all('/<input type\="hidden" name\="([^"]+)".*?value\="([^"]*)"[^>]*>/si', $html, $matches);
$values = $matches[2];
$params = "";

$i=0;
foreach ($matches[1] as $name)
{
$params .= "$name=" . urlencode($values[$i]) . "&";
++$i;
}

$login = urlencode($login);
$password = urlencode($password);

curl_setopt($ch, CURLOPT_URL,$action);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params ."Email=$login&Passwd=$password&PersistentCookie=");
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__)."/cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__)."/cookie.txt");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
$html = curl_exec($ch);

#test if login was successful:
if (preg_match('/url=([^"]*)/', $html, $actionarr)!=0)
{
$location = $actionarr[1];
$location = urldecode($location);

}
else
{
return false;
}


$location2=trim(html_entity_decode($location),"\'");
preg_match_all('/continue\=(.*)$/',$location2,$matches);

$finalLocation=urldecode($matches[1][0]);

if($finalLocation!="")
{
$data=explode("?",$finalLocation);
}
else
{
$data=explode("?",$location2);
}

$ch1=curl_init();

curl_setopt($ch1, CURLOPT_URL, $data[0]);
curl_setopt($ch1, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch1, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch1, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch1, CURLOPT_HEADER, true);
curl_setopt($ch1, CURLOPT_POST, 1);
curl_setopt($ch1, CURLOPT_POSTFIELDS, $data[1]);

$html1 = curl_exec($ch1);
//echo htmlentities($html1);die('here');
$cokkies1=$this->getCookies($html1);
$location1=$this->getLocation($html1);

$ch2=curl_init();
//https://mail.google.com/mail/?ui=1&ik=3e519dfafc&view=cl&search=contacts&pnl=d&zx=z6eymy-vwj0lu
curl_setopt($ch2, CURLOPT_URL, "https://mail.google.com/mail/?ui=1&search=contacts&view=cl&pnl=d&f=1");
curl_setopt($ch2, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($ch2, CURLOPT_HEADER, true);
curl_setopt($ch2, CURLOPT_COOKIEFILE, dirname(__FILE__)."/cookie.txt");
curl_setopt($ch2, CURLOPT_COOKIEJAR, dirname(__FILE__)."/cookie.txt");
curl_setopt($ch2, CURLOPT_FOLLOWLOCATION,1);

$html2 = curl_exec($ch2);

ini_set('xdebug.var_display_max_data', 5000);
preg_match_all('/\-\-\>\<\/script\>\<script\>\<!\-\-\s([\[\]\,\"\s\W\@\-\._a-zA-Z0-9]*)\)\;[\s]*\/\//',$html2,$matches);
preg_match_all('/([\[\]\"\,\@\.\-\(\)\s\W_a-zA-Z0-9]*?)\;/',$matches[1][0],$matches);
$email_info=array();
foreach($matches[1] as $item){
preg_match('/D\(([\"\[\]\,\@\.\-\s\W_a-zA-Z0-9]*)\)/',$item,$result);
$email_info=json_decode($result[1],true);
foreach($email_info as $user){
if($user[2]){
$email_list[]=$user[2];
}
if($user[4]){
$name_list[]=$user[4];
}
}
}

$address=array();

$address=array('name'=>$name_list,'email'=>$email_list);
return $address;
}



}
?>

  6. Re: Grab Gmail Contacts not working   Reply   Report abuse  
Picture of rosemathi121 rosemathi121 - 2009-02-19 11:59:02 - In reply to message 5 from qunxyz
not working gmail orkut etc.. help me

  7. Re: Grab Gmail Contacts not working   Reply   Report abuse  
Picture of mithilesh mithilesh - 2009-02-22 06:42:25 - In reply to message 1 from Billy
its working fine for me.

  8. Re: Grab Gmail Contacts not working   Reply   Report abuse  
Picture of steph c steph c - 2009-03-13 04:25:18 - In reply to message 5 from qunxyz
this is working, contacts are returned. but almost all the names are mismatched to the addresses. hope someone can fix it.

email:stepanya@gmail.com

  9. Re: Grab Gmail Contacts not working   Reply   Report abuse  
Picture of Francisco Antonio Vieira Souza Francisco Antonio Vieira Souza - 2009-03-31 17:15:42 - In reply to message 5 from qunxyz
Hi there, I am informing my correct login data, however it does not connect.

The piece of code below shows 'NOT CONNECTED' (all the rest is exactly like yours).

#test if login was successful:
if (preg_match('/url=([^"]*)/', $html, $actionarr)!=0){
$location = $actionarr[1];
$location = urldecode($location);
echo "CONNECTED SUCCESSFULLY <BR><BR>";
} else {
echo "NOT CONNECTED<BR><BR>";
return false;
}

  10. Re: Grab Gmail Contacts not working   Reply   Report abuse  
Picture of chaitanyad chaitanyad - 2009-07-29 12:17:41 - In reply to message 5 from qunxyz
i would retrive only one contact details ,, if iam testing with other mail id's i can see the first id contact details .. please help me

 
  1 - 10   11 - 11