Step 1
Add or register your domain at click here.
Step 2
Verify your domain ownership with HTML file upload or including META tag.
Step 3
Google will provide you OAuth consumer key and OAuth consumer secret key.
Step 4
Create client ID OAuth Console here.![Login with Google Plus Oauth](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhscC-cMVg5Q1ISY1Qkl6ayY0CtgzCygTJoobxeUI945cEGZmTnIYFKlYc1pYylGVwD0uYhC8Tswt3N5a3du91i_yYsHDgMIPpV43QRl04DrIAadVnRgINeGj8qxI1b-rDz2j5bxOn3zOfm/s506/step4.png)
Step 5
Create client ID.![Login with Google Plus OAuth.](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhNRxpUnUdBIQ9J_PwUi2D1E7PhmP71b9dEK_Drao61qCucRKGMm27Owq839pZ7sbthUkKE1KeEn7cSlVvC1sFpj-2q_9uluzfSSq35MDhaZY9m1IaSVIZQOHEZNrxiJRcN6So689CDgHIL/s552/step5.png)
Step 6
Here the application OAuth client ID and client secret.![Login with Google Plus OAuth.](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRGZ5DsSjocinjqFKZ7bKUCIlEAwNHzSHIh-mbdOJcP9s1sGYznPsSNpsNgfwBNhbWvCjfUC0pLP5yxIz8V4dh0NJ4cccVi9iYYdV6k5rMNwo1XVUYNWewNgT9i84mg6jARopO27tGnrD6/s517/step6.png)
Config.php
Here you have to configure application OAuth keys and Consumer keys.
// OAuth2 Settings, you can get these keys at https://code.google.com/apis/console Step 6 keys
'oauth2_client_id' => 'App Client ID',
'oauth2_client_secret' => 'App Client Secret',
'oauth2_redirect_uri' => 'http://yoursite.com/gplus/index.php',
// OAuth1 Settings Step 3 keys.
'oauth_consumer_key' => 'OAuth Consumer Key',
'oauth_consumer_secret' => 'OAuth Consumer Secret',
'oauth2_client_id' => 'App Client ID',
'oauth2_client_secret' => 'App Client Secret',
'oauth2_redirect_uri' => 'http://yoursite.com/gplus/index.php',
// OAuth1 Settings Step 3 keys.
'oauth_consumer_key' => 'OAuth Consumer Key',
'oauth_consumer_secret' => 'OAuth Consumer Secret',
gplus_login.php
Google plus login system.
<?php
require_once 'src/apiClient.php';
require_once 'src/contrib/apiPlusService.php';
session_start();
$client = new apiClient();
$client->setApplicationName("9lessons Google+ Login Application");
$client->setScopes(array('https://www.googleapis.com/auth/plus.me'));
$plus = new apiPlusService($client);
if (isset($_REQUEST['logout']))
{
unset($_SESSION['access_token']);
}
if (isset($_GET['code']))
{
$client->authenticate();
$_SESSION['access_token'] = $client->getAccessToken();
header('Location: http://' . $_SERVER['HTTP_HOST'] .$_SERVER['PHP_SELF']);
}
if (isset($_SESSION['access_token']))
{
$client->setAccessToken($_SESSION['access_token']);
}
if ($client->getAccessToken())
{
$me = $plus->people->get('me');
$_SESSION['access_token'] = $client->getAccessToken();
}
else
$authUrl = $client->createAuthUrl();
if(isset($me))
{
$_SESSION['gplusdata']=$me;
header("location: home.php");
}
if(isset($authUrl))
print "<a class='login' href='$authUrl'>Google Plus Login </a>";
else
print "<a class='logout' href='index.php?logout'>Logout</a>";
?>
require_once 'src/apiClient.php';
require_once 'src/contrib/apiPlusService.php';
session_start();
$client = new apiClient();
$client->setApplicationName("9lessons Google+ Login Application");
$client->setScopes(array('https://www.googleapis.com/auth/plus.me'));
$plus = new apiPlusService($client);
if (isset($_REQUEST['logout']))
{
unset($_SESSION['access_token']);
}
if (isset($_GET['code']))
{
$client->authenticate();
$_SESSION['access_token'] = $client->getAccessToken();
header('Location: http://' . $_SERVER['HTTP_HOST'] .$_SERVER['PHP_SELF']);
}
if (isset($_SESSION['access_token']))
{
$client->setAccessToken($_SESSION['access_token']);
}
if ($client->getAccessToken())
{
$me = $plus->people->get('me');
$_SESSION['access_token'] = $client->getAccessToken();
}
else
$authUrl = $client->createAuthUrl();
if(isset($me))
{
$_SESSION['gplusdata']=$me;
header("location: home.php");
}
if(isset($authUrl))
print "<a class='login' href='$authUrl'>Google Plus Login </a>";
else
print "<a class='logout' href='index.php?logout'>Logout</a>";
?>
home.php
Contains PHP code inserting Google plus session details into users table.
<?php
session_start();
if (!isset($_SESSION['gplusdata']))
{
// Redirection to home page
header("location: index.php");
}
else
{
$me=$_SESSION['gplusdata'];
echo "<img src='$me['image']['url']; ' />";
echo "Name: $me['displayName']; ";
echo "Gplus Id: $me['id']";
echo "Male: $me['gender']";
echo "Relationship: $me['relationshipStatus']";
echo "Location: $me['placesLived'][0]['value']";
echo "Tagline: $me['tagline'];
print "<a class='logout' href='index.php?logout'>Logout</a> ";
}
?>
session_start();
if (!isset($_SESSION['gplusdata']))
{
// Redirection to home page
header("location: index.php");
}
else
{
$me=$_SESSION['gplusdata'];
echo "<img src='$me['image']['url']; ' />";
echo "Name: $me['displayName']; ";
echo "Gplus Id: $me['id']";
echo "Male: $me['gender']";
echo "Relationship: $me['relationshipStatus']";
echo "Location: $me['placesLived'][0]['value']";
echo "Tagline: $me['tagline'];
print "<a class='logout' href='index.php?logout'>Logout</a> ";
}
?>
No comments:
Post a Comment