Skip to content Skip to sidebar Skip to footer
Reading Time: 2 minutes

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.


First you must add or manage the domain name in the Google account by using following url.
More Information about this.
1-Add your domain name here.
Add or Manage a Domain name-Google

2-Verify your domain name(if added new domain name).

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.

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

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


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.


Creating the GmailOath.phpfile.


Creating Contacts.php file.

$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"] ."
"; } }?>


Finally Create index.php file.

get_request_token($oauth, false, true, true);
//get access to Gmail
 Connect me with Gmail 

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