GMail Contact List (Address Book) Grabber

Compared to the MSN and AIM contact grabbing classes interacting with Gmail was an absolute pleasure thanks to the hard work of at least two people truly deserving of thanks.

Y. H. Gan and Neerav Modi have produced an immensely powerful script for interacting with Gmail. It does far more than just grabbing the contact list. Using it feels a lot like using a swiss army knife or maybe one of those swanky Leathermans when a screwdriver will do just fine.

Grab the Script

The libgmailer script you’ll need can be downloaded from here. Grab that and then return for instructions on how to grab the contact list.

Grabbing the contact list

The code you need to retrieve the Gmail contact list with this script is as follows.



$gmail_acc = "username";
$gmail_pwd = "acc_pass";
$my_timezone = 0;
$gmailer = new GMailer();
if ($gmailer->created) {
$gmailer->setLoginInfo($gmail_acc, $gmail_pwd, $my_timezone);

//uncomment if you need it

if ($gmailer->connect()) {
// GMailer connected to Gmail successfully.
// Do something with it.

//Get the contacts
// For "Inbox"

$gmailer->fetchBox(GM_CONTACT, "all", "");

$snapshot = $gmailer->getSnapshot(GM_CONTACT);

//Outputs an array of the contacts

//Outputs the number of contacts

} else {
die("Fail to connect because: ".$gmailer->lastActionStatus());
} else {
die("Failed to create GMailer because: ".$gmailer->lastActionStatus());


That’s it! It’s a bit more complex than for some of the other scripts but that’s what happens when you use such a powerful package for something simple. The only drawback with this script is that it requires CURL but I think most hosts have this installed so it’s unlikely to be a problem.

If you do have any problems though or want to give any other sort of feedback please post it in the comments of this thread.

8 Responses to GMail Contact List (Address Book) Grabber

  1. knuckled ortalidae jovialness locational fumigatorium cringe decreet thickety
    Mika’s Pocket Holsters

  2. vijaya says:

    I am using the same script to fetch the contact but it is printing NULL NULL.

    var_dump($snapshot->contacts_total); both these statements are returning NULL.

    Please put me some suggestions.

  3. Swetadri says:

    Is there any wat to fetch contact list from gmail using java program?I need same program in java for my project.

  4. Stjepan says:

    I have the same problem like vijaya!

  5. I want it for my Linowis website, but when i run script it shows error,

    Call-time pass-by-reference has been deprecated; If you would like to pass it by reference, modify the declaration of [runtime function name](). If you would like to enable call-time pass-by-reference, you can set allow_call_time_pass_reference to true in your INI file in

    can we have any such script that does not use CURL

  6. flesik says:

    That is nice, similar script is available on

  7. vaishali says:

    I am facing the same problem like vijaya..
    when i run this code it will give me an error like

    GMailSnapshot Object ( [created] => 0 [snapshot_error] => Invalid response from Gmail (empty) )

    why is it happens?
    please reply soon with solution..

  8. frozenade says:

    It seems Google returns something that not expected by script. Perhaps Google is not available for this code anymore.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: