Gmail contactlist reader with Google Oauth API in php
Gmail contactlist reader with Google Oauth API will helps us to read the contact list of our friends with Google authenticate method.These days it is very important to share,invites ,sending email through many application with your friend list .So the Google Oauth will solve this requirement.
First of all you have to signup with Google to your application reads the Gmail contact list.For signup you application on Google check here.
When you register your application with Google you will get one Consumer key and secret key. Then you have to download the Gmail contactlist reader Google Oauth API config file. Gmailconfig.
When you get the Google API keys and config file then you can start the integration of Gmail Oauth API with php. First you have to create a php file for user interface and have the following codes.Also make sure you created a folder with Gmail_api in your file structure.
<?php
session_start();
require_once('Gmail_api/Gmailconfig.php');
$cuncumer_key='YOUR_CONSUMER_KEY';
$cunsumer_secret='SECRET_KEY';
$argarray = $argv[0];
$debug = 0; // Set to 1 for verbose debugging output
$callback = "http://www.yourdomain.com/gmail_callback.php";
$oauth =new GmailOath($cuncumer_key, $cunsumer_secret, $argarray, $debug, $callback);
//echo $oauth->oauth_cunsumer_secret;
$getcontact=new GmailGetContacts();
$accrss_token=$getcontact->get_request_token($oauth, false, true, true);
$_SESSION['oauth_token'] = $accrss_token['oauth_token'];
$_SESSION['oauth_token_secret'] = $accrss_token['oauth_token_secret'];
$urls_ = "https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token=".$oauth->rfc3986_decode($accrss_token['oauth_token']);
$gmail_link = '<a href="'.$urls_.'">Gmail Contacts</a>';
echo $gmail_link;
?>
When you create these file it will get the Google Oauth user authentication but in the above file you are already give one call back file so next step is to create gmail_callback.php and have the following codes.
<?php
session_start();
require_once('Gmail_api/Gmailconfig.php');
$cuncumer_key='CONSUMER_KEY';
$cunsumer_secret='SECRET_KEY';
$argarray = $argv[0];
$debug = 0; // Set to 1 for verbose debugging output
$callback = "http://www.yourdomain.com/gmail_callback.php";
$oauth =new GmailOath($cuncumer_key, $cunsumer_secret, $argarray, $debug, $callback);
$getcontact_access=new GmailGetContacts();
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Get the access token using HTTP GET and HMAC-SHA1 signature
$request_token=$oauth->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);
////////////////////////////////////////////////////////////////////
$access_token=$oauth->rfc3986_decode($retarr['oauth_token']);
//echo "Access token :".$access_token;
//echo "<br />";
$access_token_secret=$oauth->rfc3986_decode($retarr['oauth_token_secret']);
//echo "access token sectet :".$access_token_secret;
//echo "<br />";
$contac_list= $getcontact_access->callcontact($oauth, $access_token, $access_token_secret, false, true);
$gmailList = "";
foreach($contac_list as $k => $value)
{
$user_full_name = $value['title']['$t'];
foreach($value['gd$email'] as $email)
{
//echo $email["address"]."<br/>";$user_full_name."<".$email["address"].">";
$gmailList.= "<div><span>".$user_full_name."</span><span>".$email["address"]."</span></div>";
}
}
//$full_string = implode(",",$gmailList);
echo $gmailList;
?>
For your reference check here. Also make sure you are running the application on the registered application url other wise it will not authenticate eg: (when your application registered with http://yourdomain.com and try to access with http://www.yourdomain.com then it will not works Google or any other Oauth methods.). for clearing the work flow from Google check here
Also you can play on the Google play ground for Oauth check here.
11 thoughts on “Gmail contactlist reader with Google Oauth API in php”
I want to get Google account full name by google client id / secret key
Please help me out
Thanks in advanced.
Sandeep
I couldn’t find a download file of gmail config or there is no full source code as others such as yahoo or hot mail has. Please provide source code link.
Its already there in this link http://www.walkswithme.net/gmail-contactlist-reader-with-google-oauth-api-in-php/gmailconfig
Yea, It hard to noticed, added a download link too.
Thanks for your reply.
Sorry if I am wrong, still I can’t find link or file. I tried the link http://www.walkswithme.net/gmail-contactlist-reader-with-google-oauth-api-in-php/gmailconfig , but the page with heading “One thought on Gmailconfig” showing a comment “nice” , its reply form and a link above for back to the main page only. Some other pages for eg: hotmail http://www.walkswithme.net/hotmail-contact-list-reader-api-in-php-msn-oauth has demo link and download link nearby above the comments. If you can please send the file to may email id.
Oh you missed it again.
The link I sent you had a link like Gmail contactlist reader with Google Oauth API in php “gmailconfig ” the last word is download link. its difficult to find that’s why I added download option in this page . You missed that too.
Anyway you can download using this Download
this is still working?
Yes, few alteration in the App creation method, but same code works fine.
Can we get Phone numbers of persons in our contact list using Gmail Oauth
No, using Gmail Oauth Api you can’t get users phone number.
how can i retrive user which sign in email address
Once you authenticate with Oauth API,
send a request to this url it will return current users profile , Keep in mind while creating Google APP you should set the permission to read profile.
https://www.googleapis.com/auth/userinfo.profile