Invite friends from Gmail

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.

config.php

In this file you have to enter Client ID, Client secret and Redirect URIs.

http://your path/result.php'; 
$maxresults = 50; // Number of mailid you want to display.
?>


index.php


https://accounts.google.com/o/oauth2/auth?client_id=
&redirect_uri=
&scope=https://www.google.com/m8/feeds/&response_type=code">
Invite Friends From Gmail


result.php

 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_URL,'https://accounts.google.com/o/oauth2/token');
curl_setopt($ch,CURLOPT_POST,5);
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);.
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);

$response = json_decode($result);
$accesstoken = $response->access_token;
if( $accesstoken!='')
$_SESSION['token']= $accesstoken;
$xmlresponse= file_get_contents('https://www.google.com/m8/feeds/contacts/
default/full?max-results='.$maxresults.'&oauth_token='. $_SESSION['token']);

$xml= new SimpleXMLElement($xmlresponse);
$xml->registerXPathNamespace('gd', 'http://schemas.google.com/g/2005');
$result = $xml->xpath('//gd:email');
$count = 0;
foreach ($result as $title) {
$count++;
echo $count.". ".$title->attributes()->address . "

"; } ?>

 

Contact the Author

Please sign in to contact this author.

This item is one of the free files. You are able to download this item for free for a limited time. Updates and support are only available if you purchase this item.

Price Details
Regular License
₹60

License Agreement

3 Sales
( 0 Ratings )
0 Comments
Item Information
Last Update
03 Oct 2024


Created
26 Sep 2019


Category
PHP Scripts


Compatible Browsers
Opera,
Chrome,
Firefox


Package Includes
CSS,
HTML
Back To Top