I have successfully created the API registration in GOOGLE. To login on my website I use this link:
https://accounts.google.com/o/oauth2/auth?response_type=code&redirect_uri=http://www.example.com/goo/gaccess.php&client_id=109717......9-0r0..............avubqdddi5j.....apps.googleusercontent.com&scope=email
After clicking on this link Google asks to accept if you want to allow this app to access your info. After clicking accept User redirect to the page where I have added my script.
<?php
require_once realpath(dirname(__FILE__) . '/google-api-php-client-master/src/Google/autoload.php'); // or wherever autoload.php is located
if (isset($_GET['code'])) {
echo $access_token = $_GET['code'];
$client->authenticate($_GET['code']);
$_SESSION['access_token'] = $client->getAccessToken();
$redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
}
?>
The problem is I don't know what to do to get the users info and email id. I want to show it to the users after they accept to give the access of their information to my website. What I am getting now is only a code:
4/v3Lbc...............o15_kBpgqItOOcR-BAm9FA.ksVbL...............KaDJMaXmAI
Also I have installed a PHP client library for accessing Google APIs.
You use to use this code as stated in sample project here
if ($client->getAccessToken()) {
$user = $oauth2->userinfo->get();
// These fields are currently filtered through the PHP sanitize filters.
// See http://www.php.net/manual/en/filter.filters.sanitize.php
$email = filter_var($user['email'], FILTER_SANITIZE_EMAIL);
$img = filter_var($user['picture'], FILTER_VALIDATE_URL);
$personMarkup = "$email<div><img src='$img?sz=50'></div>";
// The access token may have been updated lazily.
$_SESSION['token'] = $client->getAccessToken();
}