PHP Classes

gmail access problem

Recommend this page to a friend!

      Contact Grabber  >  All threads  >  gmail access problem  >  (Un) Subscribe thread alerts  
Subject:gmail access problem
Summary:No contacts are displayed
Messages:7
Author:yalamber
Date:2008-01-31 14:01:20
Update:2010-02-04 11:48:03
 

  1. gmail access problem   Reply   Report abuse  
Picture of yalamber yalamber - 2008-01-31 14:01:22
Hello i have problem with gmail importer. It's not importing gmail addressbook.

  2. Re: gmail access problem   Reply   Report abuse  
Picture of esadot esadot - 2008-02-05 14:49:15 - In reply to message 1 from yalamber
You may find this helpful https://sourceforge.net/forum/forum.php?thread_id=1915541&forum_id=694037

  3. Re: gmail access problem   Reply   Report abuse  
Picture of freshcn freshcn - 2008-03-05 09:00:57 - In reply to message 1 from yalamber
<?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();
curl_setopt($ch, CURLOPT_URL,"http://mail.google.com/mail/");
curl_setopt($ch, CURLOPT_REFERER, "");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'read_header');

#get the html from gmail.com
$html = curl_exec($ch);

$matches = array();
$actionarr = array();

$action = "https://www.google.com/accounts/ServiceLoginAuth?service=mail";

#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);

#submit the login form:
curl_setopt($ch, CURLOPT_URL,$action);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params ."Email=$login&Passwd=$password&PersistentCookie=");

$html = curl_exec($ch);

#test if login was successful:
if (!isset($cookiearr['GX']) && (!isset($cookiearr['LSID']) || $cookiearr['LSID'] == "EXPIRED"))
{
return 1;
}

#this is the new csv url:
curl_setopt($ch, CURLOPT_URL, "http://mail.google.com/mail/contacts/data/export?exportType=ALL&groupToExport=&out=OUTLOOK_CSV");
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);

$html = curl_exec($ch);

$csvrows = explode("\n", $html);
array_shift($csvrows);

$result = array();
$result['name'] = array();
$result['email'] = array();
foreach ($csvrows as $row)
{
$values = explode(",", $row);
if (eregi("@", $values[1]))
{
$result['name'][] = ( trim($values[0])=="" ) ? $values[1] : $values [0];
$result['email'][] = $values[1];
}
}

return $result;
}



}


#read_header is essential as it processes all cookies and keeps track of the current location url
#leave unchanged, include it with get_contacts
function read_header($ch, $string)
{
global $location;
global $cookiearr;
global $ch;

$length = strlen($string);
if(!strncmp($string, "Location:", 9))
{
$location = trim(substr($string, 9, -1));
}
if(!strncmp($string, "Set-Cookie:", 11))
{
$cookiestr = trim(substr($string, 11, -1));
$cookie = explode(';', $cookiestr);
$cookie = explode('=', $cookie[0]);
$cookiename = trim(array_shift($cookie));
$cookiearr[$cookiename] = trim(implode('=', $cookie));
}
$cookie = "";
if(trim($string) == "")
{
foreach ($cookiearr as $key=>$value)
{
$cookie .= "$key=$value; ";
}
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
}

return $length;
}

#function to trim the whitespace around names and email addresses
#used by get_contacts when parsing the csv file
function trimvals($val)
{
return trim ($val, "\" \n");
}

?>

  4. Re: gmail access problem   Reply   Report abuse  
Picture of albert takacs albert takacs - 2008-05-14 17:15:00 - In reply to message 3 from freshcn
I try to use this script but i get this message:

Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when in safe_mode or an open_basedir is set in
home/..../gmail/libgmailer.php on line 186

  5. Re: gmail access problem   Reply   Report abuse  
Picture of Himanshu Panjwani Himanshu Panjwani - 2008-10-14 06:44:01 - In reply to message 3 from freshcn
hi sir mam, i m from india. and i found today your website reference. sir i also installed the email address grabber zip file. but after that what i do i dont know. would please tell me how can this zip file work for grab the data. i think this a software language. i dont know this language but please guide me i need urgently my id email addresses.

regards
Hunny
if possible then please direct reply me on this id
hunnypanjwani@yahoo.co.in

  6. Re: gmail access problem   Reply   Report abuse  
Picture of rajesh rajesh - 2009-04-25 07:27:07 - In reply to message 3 from freshcn
I have used your coding but it shows an error as

Fatal error: Class 'baseFunction' not found

Can you please send me the class file of baseFunction.

  7. Re: gmail access problem   Reply   Report abuse  
Picture of Chinnasamy Chinnasamy - 2010-02-04 11:48:03 - In reply to message 3 from freshcn
where is baseFunction class