Hello,
I'm trying gmail login on my website. i used Oauth2 for this.
http://www.idiotminds.com/sign-in-with-google-account-using-oauth2-0/
Here process is working fine but i don't getting any data from the service like username , email etc. no any data is returning for me
http://22yardscricket.com/gmaillogin/index.php
Here is my code:
config.php:
<?php
/*
------------------------------------------------------
www.idiotminds.com
--------------------------------------------------------
*/
session_start();
$base_url= filter_var(
// Visit https://code.google.com/apis/console to generate your
// oauth2_client_id, oauth2_client_secret, and to register your oauth2_redirect_uri.
define(
define(
define(
define(
define(
?>
index.php:
= newsetApplicationName("Google UserInfo PHP Starter Application");
$client->setClientId(CLIENT_ID);
$client->setClientSecret(CLIENT_SECRET);
$client->setRedirectUri(REDIRECT_URI);
$client->setApprovalPrompt(APPROVAL_PROMPT);
$client->setAccessType(ACCESS_TYPE);
$oauth2 = new Google_Oauth2Service($client);
if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['token'] = $client->getAccessToken();
echo '<script type="text/javascript">window.close();</script>'; exit;
}
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
}
if (isset($_REQUEST['error'])) {
echo '<script type="text/javascript">window.close();</script>'; exit;
}
if ($client->getAccessToken()) {
$user = $oauth2->userinfo->get();
$sql="INSERT INTO users (name,email,gender) VALUES ('".$user['name']."','".$user['email']."','".$user['gender']."')";
mysql_query($sql);
// 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>";
$_SESSION["email"] = $email;
$_SESSION["name"] = $user['name'];
echo "<script>alert('".$email."');</script>";
// The access token may have been updated lazily.
$_SESSION['token'] = $client->getAccessToken();
} else {
$authUrl = $client->createAuthUrl();
}
?>
<!doctype html>
<html>
<head><meta charset="utf-8">
<title>Signin with Google Account-Idiot Minds</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="js/oauthpopup.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('a.login').oauthpopup({
path: '',
width:650,
height:350,
});
$('a.logout').googlelogout({
redirect_url:'logout.php'
});
});
</script>
</head>
<body>
<div style="float:left;width:33%;margin-left:375px;">
='login'='javascript:void(0);'<img alt='Signin in with Google' src='signin_google.png'/></a>";
} else {
print "<a class='logout' href='javascript:void(0);'>Logout</a>";
}
?>
</div>
</body></html>
kindly suggest.
Regards,
Harish