PHP Import Email Addresses from Gmail Accounts

How to import user email addresses from gmail account using php.Now I’m going to explain how to import email addresses using google auth API.
The Google Contacts Data API allows client applications to view and update a user’s contacts. Contacts are stored in the user’s Google Account; most Google services have access to the contact list.

Step-1

First you must add or manage the domain name in the Google account by using following url.
https://accounts.google.com/ManageDomains
More Information about this.
http://code.google.com/apis/accounts/docs/RegistrationForWebAppsAuto.html
1-Add your domain name here.
Add or Manage a Domain name-Google

2-Verify your domain name(if added new domain name).
Add-or-Manage-Domain-name-step-2

3-After the successfully message click in the “Continue” link.Then display a new page to Agreement.But still domain name is inactive status.Click that button to agree and manage the domain name.
Add-or-Manage-Domain-name-3

4-Now fill the fields in the manage domain name page.Then click in the “Save” Button.
Add-or-Manage-Domain-name-4

5-After save,you can view your “Consumer Key” and “Consumer Secret”.Copy these info and paste in your config file.
Add-or-Manage-Domain-name-5

Step-2

Ok.Now Domain name is created.Then check php_curl extension is enabled in the web server.
Add your keys in the Config.php file.


Step-3

Creating the GmailOath.phpfile.

Step-4

Creating Contacts.php file.

rfc3986_decode($_GET['oauth_token']);
$request_token_secret	=	$oauth->rfc3986_decode($_SESSION['oauth_token_secret']);
$oauth_verifier	= $oauth->rfc3986_decode($_GET['oauth_verifier']);
$retarr = $getcontact_access->get_access_token($oauth,
                           $request_token, $request_token_secret,
                           $oauth_verifier, false, true, true);
/* ****************************************
	// Call Contact API
 **************************************** */
$access_token	=	$oauth->rfc3986_decode($retarr['oauth_token']);
$access_token_secret	=	$oauth->rfc3986_decode($retarr['oauth_token_secret']);
$contacts	=	$getcontact_access->callcontact($oauth, $access_token, $access_token_secret, false, true);
//display Email Contacts
foreach($contacts as $key => $val)
{
	$final = end($contacts[$key]);
	foreach($final as $email)
	{
		echo $email["address"] ."
"; } }?>

Step-5

Finally Create index.php file.

get_request_token($oauth, false, true, true);
//********************************
//get access to Gmail
//********************************
$_SESSION['oauth_token']=$accrss_token['oauth_token'];
?>
 Connect me with Gmail 

That’s all.
View Demo
Download Source(8.5 KB)