I have a problem and it took a couple of days without finding a solution, I want to put the facebook login button on my website and I have managed to get the email but only in the development phase when I put the application in real no longer captures me the email, you only get the email from the developer accounts and I need to be able to catch the email in order to make a user registration when you log in for the first time with your facebook account, any help is well received, thanks!
function statusChangeCallback(response)
{
console.log('statusChangeCallback');
console.log(response);
if (response.status === 'connected')
{
testAPI();
}
else if (response.status === 'not_authorized')
{
document.getElementById('status').innerHTML = 'Inicia sesión';
}
else
{
document.getElementById('status').innerHTML = 'Inicia sesión';
}
}
function checkLoginState()
{
FB.getLoginStatus(function(response){
statusChangeCallback(response);
});
}
window.fbAsyncInit = function()
{
FB.init({
appId : 'xxxxxxxxxxxxxxxx',
cookie : true, // enable cookies to allow the server to access
// the session
xfbml : true, // parse social plugins on this page
version : 'v2.5' // use version 2.5
});
};
function login_fb()
{
FB.login(function(response){
validarUsuario();
}, {scope: 'public_profile, email'});
}
function validarUsuario()
{
FB.getLoginStatus(function(response) {
if(response.status == 'connected') {
testAPI();
} else if(response.status == 'not_authorized') {
alert('Debes autorizar la app!');
} else {
alert('Debes ingresar a tu cuenta de Facebook!');
}
});
}
// Load the SDK asynchronously
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/es_ES/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
function testAPI() {
console.log('Bienvenido ');
FB.api('/me?fields=name,email,first_name,last_name', function(response) {
console.log('Este es el email: ' + response.email);
});
}