Google has introduced OAuth 2.0 and OAuth 1.0 has been officially deprecated as of April 20, 2012. So let us create a program to invite friends from Gmail using OAuth 2.0. Before you can use OAuth 2.0, you must register your application using the Google APIs Console. First you need to create a project and follow the steps.

Create a New project:
Invite friends from Google

Then Click on API Access to Create an OAuth 2.0 Client ID
Invite Friends

Fill up the form to create your project
Gmail friend list

Setting your Client ID
Gmail contact list in php

Now you will get your Client ID, Client secret and Redirect URIs that we will use in our project. You can edit your Redirect URIs by clicking on Edit Setting in the right side. Once you have all info lets create our conig.php file.


In this file you have to enter Client ID, Client secret and Redirect URIs.
$clientid = 'Your Client here';
$clientsecret = 'Your Client Secret';
$redirecturi = 'http://your path/result.php'; 
$maxresults = 50; // Number of mailid you want to display.


<?php include('config.php'); ?>
<a href="
<?php print $clientid;?>&redirect_uri=<?php print $redirecturi; ?>
Invite Friends From Gmail</a>

$authcode = $_GET["code"];
'code'=> urlencode($authcode),
'client_id'=> urlencode($clientid),
'client_secret'=> urlencode($clientsecret),
'redirect_uri'=> urlencode($redirecturi),
'grant_type'=> urlencode('authorization_code') );

$fields_string = '';
foreach($fields as $key=>$value){ $fields_string .= $key.'='.$value.'&'; }
$fields_string = rtrim($fields_string,'&');

$ch = curl_init();//open connection
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);.
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);

$response = json_decode($result);
$accesstoken = $response->access_token;
if( $accesstoken!='')
$_SESSION['token']= $accesstoken;
$xmlresponse= file_get_contents('
default/full?max-results='.$maxresults.'&oauth_token='. $_SESSION['token']);

$xml= new SimpleXMLElement($xmlresponse);
$xml->registerXPathNamespace('gd', '');
$result = $xml->xpath('//gd:email');
$count = 0;
foreach ($result as $title) {
echo $count.". ".$title->attributes()->address . "<br><br>";

Other Related Topics

Import Contacts from Hotmail
Import Contacts from Yahoo!

Download File

Total Downloads: 3894