Utilizing the Facebook authentication feature on my website through javascript sdk, I am able to retrieve my own email and name. However, when users log in, only their names are accessible (since it's linked to my fb developer app).
Despite prompting for login, nothing occurs if no one is currently logged into Facebook. Strangely, inserting an alert at the login section shows the name but not the email. Surprisingly, when testing with my own account, both email and name are successfully retrieved. Why does this discrepancy exist?
Below is a snippet of my code:
<%-- Facebook connection script --%>
<script src="//connect.facebook.net/en_US/all.js"></script>
<script> FB.init({
appId: '334351783684824',
cookie: true,
xfbml: true,
version: 'v2.8'
});
function fbAuthUser() {
FB.login(checkLoginStatus);;
}
function checkLoginStatus(response) {
if (response.status === 'connected') {
FB.api('/me', 'GET', { fields: 'email,name' }, function (response) {
alert(response.email + "; " + response.name);
Ajax(response.email, response.name);
});
}
}
function Ajax(expressao1, expressao2) {
var request = { email: expressao1, nome: expressao2 }
$.ajax({
url: 'login.aspx/LoginExterno',
method: 'post',
contentType: 'application/json',
data: JSON.stringify(request),
dataType: 'json',
success: function (resp) {
window.location.href = resp.d;
},
error: function () { }
})
}
</script>
The intended process is to login, then upon receiving the data, execute the ajax function to access a C# code behind function that redirects users to either the index page if they have an existing account or the registry page if not. The issue lies in the fact that the email parameter remains undefined, preventing entry into the Ajax function. However, the function executes successfully when both email and name are present.
What steps can be taken to properly retrieve the user's email?