|
jimmy - 2008-10-29 20:43:38
<?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 error code if they weren't
return 2;
}
#initialize the curl session
$ch = curl_init();
#submit the login form:
curl_setopt($ch, CURLOPT_URL,"https://www.google.com/accounts/ClientLogin");
curl_setopt($ch, CURLOPT_REFERER, "");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array("Email"=> $login, "Passwd" => $password, "service" => "cp", "source" => "testCo-myApp-1"));
$html = curl_exec($ch);
$Auth = strstr($html, "Auth=");
#test if login was successful:
if(!$Auth) {return 1;}
$Auth = substr($Auth, 5);
$Auth = trim($Auth);
#this is the contact url:
curl_setopt($ch, CURLOPT_URL, "http://www.google.com/m8/feeds/contacts/".urlencode($login)."/full");
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: GoogleLogin auth='.$Auth));
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPGET, 1);
$html = curl_exec($ch);
$rows = explode("<entry>", $html);
array_shift($rows);
$result = array();
$result['name'] = array();
$result['email'] = array();
foreach($rows as $contents){
$result['name'][] = text_extract($contents, "<title type='text'>", "</title>");
$result['email'][] = text_extract($contents, "address='", "' primary='");
}
return $result;
}
}
function text_extract($string,$ot,$ct)
{
$string = trim($string);
$start = intval(strpos($string,$ot) + strlen($ot));
$mytext = substr($string,$start,intval(strpos($string,$ct) - $start));
return $mytext;
}
?>
wooloo wooloo - 2008-11-08 23:01:05 - In reply to message 1 from jimmy
doesn't work
jimmy - 2008-11-09 16:01:47 - In reply to message 2 from wooloo wooloo
interesting... Still works for me.
need to change the maximum limit in contact retrieval:
from:
curl_setopt($ch, CURLOPT_URL, "http://www.google.com/m8/feeds/contacts/".urlencode($login));
to:
curl_setopt($ch, CURLOPT_URL, "http://www.google.com/m8/feeds/contacts/".urlencode($login)."/full?max-results=10000");
Might need to change the company name to yours as well.
From: testCo-myApp-1
TO: <whatever>
imran ghafoor - 2009-02-09 08:20:04 - In reply to message 3 from jimmy
i have tried but its not working, i also change the lines which u mentioned but still nothing happend
manish - 2009-02-11 07:21:44 - In reply to message 4 from imran ghafoor
i have got some problem. i m not extract gmail address by this class.
mithilesh - 2009-02-21 09:45:55 - In reply to message 1 from jimmy
Its really Work for Me.
check on www.datingfunda.com
Adrian Marriae - 2009-04-23 01:03:09 - In reply to message 1 from jimmy
this one works fine grabs contacts from the emails fine now i need to work on the others that are not working yahoo isnt working at all only seemed to work on one of my 30 email addresses and i have thousands of yahoo contacts
Gulab Pasha - 2010-12-14 11:05:10 - In reply to message 1 from jimmy
Hi,
Thanks for the code, it is working fine for me but the thing is it is only fetching 25 contacts from any gmail account.
Please help me out, how can i set it to fetch more than or full contacts.
Thanks,
Gulab Pasha
Gulab Pasha - 2010-12-14 11:08:33 - In reply to message 1 from jimmy
Hi,
I appreciate if you can send me the code for all the email provider like (aol gmail hotmail indiatimes linkedin lycos myspace orkut rediff yahoo facebook twitter)
Looking forward to your support and help.
Thanks,
Gulab Pasha
g - 2011-01-05 09:31:47 - In reply to message 7 from Adrian Marriae
well, it used to...but now it doesn't seem to work anymore....i downloaded a fresh copy of php files from here but i can't import my gmail contacts :((
|