I have enable user to get logged in via social media Facebook and google. User is getting logged in via google but cannot logged in via Facebook. When I debug my code I came to know that user's emails value is not coming. However user name is coming. So the question is how to fetch user's emails. I have the same code for google and Facebook. Here is my code :
// get social contacts with this function.(like facebook,google,yahoo)
function getLogin(network, path){
var basePath = $('#baseurl').val(); // base url
var redirectUrl = basePath+'login';
var localScope = 'email';
// initilize
hello.init({
google : 'xxxxxxxxxxxxxxxxx-xxxxxxxxxxxxxxxxmbesm1.apps.googleusercontent.com',
facebook : 'xxxxxxxxxxxxxxxxxx',
}, {
redirect_uri: redirectUrl,
scope:localScope
}
);
// login
hello.login( network, {scope:localScope}, function(auth){
if(!auth||auth.error){
return;
}
else
{
// Get Profile
hello( network ).api( '/me' , function responseHandler(p){
user = p;
var userstr="name="+user.name+"&";
userstr +="link="+''+"&";
userstr +="username="+user.displayName+"&";
userstr +="socailid="+user.id+"&"; //str +="username="+user.given_name+"&";
userstr +="email="+user.email;
// save data to google
$.post(baseURL+'social_check', {email:user.email,socialid:user.id}, function(resp){
if(resp === 'true')
{
window.location.href = baseURL+'join';
}
else
{
$.ajax({
type: "POST",
url: baseURL+'social-signup',
dataType: 'json',
data: userstr,
success: function(response){
if(response.success == 'inactive')
{
$('#gmail-error').show().html("Your account is inactive. To activate it, please click on the activation link we sent you by email. Want us to <a href='"+baseURL+"resend-confirmation-link'>resend it</a>?");
$('#fb-error').hide();
return false;
}
else if(response.success == 'deleted'){
$('#gmail-error').show().html("Your account is inactive. To activate it, please click on the activation link we sent you by email. Want us to <a href='"+baseURL+"resend-confirmation-link'>resend it</a>?");
$('#fb-error').show();
return false;
}
else if(response.success=='error')
{
$('#gmail-error').show().text("We don't recognize this account - please sign up with it on the sign-up screen first.");
$('#fb-error').hide();
return true;
}
else if(response.success == 'not-inserted'){
$('#gmail-error').show().text("Something went wrong.");
$('#fb-error').hide();
return false;
}
// if redirect url is not set
if(response.success===false)
{
$('#fb-root').hide(); $('#status').hide();
window.location.href = baseURL;
}
else{
$('#fb-root').hide(); $('#status').hide();
window.location.href = baseURL+response.success;
}
},
error: function(response)
{
$('#gmail-error').show().text("Oops something went wrong. Please try one more time.");
$('#fb-error').hide();
return false;
}
});
}
});
});
}
});
}
</script>
userstr +="email="+user.email; this is coming blank. What could I do get email of users. Any help would be highly appreciable. If anybody have an idea kindly help me out.