Jump to content

Get Gmail Contacts


The Little Guy

Recommended Posts

I am writing a google contact API to get users contacts, I get everything back except for the email address of the contact.

 

Anyone know how to get the contacts email address?

 

<?php
class gdata{
private $headers;
private $googleAuth = 'http://www.google.com/m8/feeds';
private $google = 'http://www.google.com/m8/feeds/contacts/default/full';
public $token;
public function headers(){
	$this->headers['GData-Version'] = '3.0';
	$this->headers['Authorization'] = "AuthSub token=\"$this->token\"";
	$this->headers['Content-Type'] = "application/x-www-form-urlencoded";
	$this->headers['Host'] = "www.google.com";
	$this->headers['User-Agent'] = "php/".phpversion();
	$this->headers['Accept'] = "text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2";
	$this->headers['Connection'] = "keep-alive";
}
public function request_contacts($email){
	$ch = curl_init();
	$headers = array();
	foreach($this->headers as $k => $v){
		$headers[] = "$k: $v";
	}
	$url = preg_replace("/\[email_address\]/", $email, $this->google);
	echo $url;
	curl_setopt($ch, CURLOPT_URL, $this->google);
	curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
	$opt = curl_exec($ch);
	$xml = simplexml_load_string($opt);
	header("Content-type: text/plain");
	foreach($xml->entry as $user){
		//echo $user['link']
	}
	print_r($xml->entry[5]);
}
public function auth(){
	$next =  'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?a=getContacts';
	header("Location: https://www.google.com/accounts/AuthSubRequest?next=".urlencode($next)."&scope=".urlencode($this->googleAuth)."&session=1&secure=0");
}
}

$gAPI = new gdata();

if($_GET['a'] == 'getContacts'){
$gAPI->token = $_GET['token'];
$gAPI->headers();
$gAPI->request_contacts('untuned20@gmail.com');
}else{
$gAPI->auth();
}

?>

Link to comment
Share on other sites

OK, I choose to do the json method.

 

how do I access this?

stdClass Object

(

    [gd$email] => Array

)

 

 

stdClass Object
(
    [gd$etag] => "R3k-ejVSLyt7I2A9Wx9aFkUMRAM."
    [id] => stdClass Object
        (
            [$t] => http://www.google.com/m8/feeds/contacts/untuned20%40gmail.com/base/0
        )

    [updated] => stdClass Object
        (
            [$t] => 2011-03-09T15:59:36.752Z
        )

    [app$edited] => stdClass Object
        (
            [xmlns$app] => http://www.w3.org/2007/app
            [$t] => 2011-03-09T15:59:36.752Z
        )

    [category] => Array
        (
            [0] => stdClass Object
                (
                    [scheme] => http://schemas.google.com/g/2005#kind
                    [term] => http://schemas.google.com/contact/2008#contact
                )

        )

    [title] => stdClass Object
        (
            [$t] => 
        )

    [link] => Array
        (
            [0] => stdClass Object
                (
                    [rel] => http://schemas.google.com/contacts/2008/rel#photo
                    [type] => image/*
                    [href] => http://www.google.com/m8/feeds/photos/media/untuned20%40gmail.com/0
                )

            [1] => stdClass Object
                (
                    [rel] => self
                    [type] => application/atom+xml
                    [href] => http://www.google.com/m8/feeds/contacts/untuned20%40gmail.com/full/0
                )

            [2] => stdClass Object
                (
                    [rel] => edit
                    [type] => application/atom+xml
                    [href] => http://www.google.com/m8/feeds/contacts/untuned20%40gmail.com/full/0
                )

        )

    [gd$email] => Array
        (
            [0] => stdClass Object
                (
                    [rel] => http://schemas.google.com/g/2005#other
                    [address] => untuned20@gmail.com
                    [primary] => true
                )

        )

)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.