Login with facebook api does not return user email

3

Greetings galera,

I spent hours and hours researching some solution to this problem, including here on the site, but I did not find anything that would help me.

I'm implementing a facebook site registration using facebook's api directly. I can make the connection, I make the request for permission of the user and I have the user data in return. The problem is that only comes the name and id of the user, even though I pass in the scope that I want the information of email and public profile. I'm running this schedule locally on an Apache server by Xampp, can that be the problem? I made this programming directly in php and also by javascript and in both the situation is the same.

Thanks in advance for your collaboration.

Follow the code used (even available in facebook examples):

Oops, the code I am using to test is the same as the one in the face examples:

window.fbAsyncInit = function() {

FB.init({
    appId      : 1644402569130903,
    cookie     : true,  // enable cookies to allow the server to access
                    // the session
    xfbml      : true,  // parse social plugins on this page
    version    : 'v2.4' // use version 2.2
});
FB.getLoginStatus(function(response) {
    statusChangeCallback(response);
});

};

function statusChangeCallback(response) {
    console.log('statusChangeCallback');
    if (response.status === 'connected') {
        // Logged into your app and Facebook.
        testAPI();
    } else if (response.status === 'not_authorized') {
        // The person is logged into Facebook, but not your app.
        // document.getElementById('status').innerHTML = 'Please log ' +
        //   'into this app.';
        FB.login(function(response) {
            console.log(response);
        });
    } else {
         // The person is not logged into Facebook, so we're not sure if
         // they are logged into this app or not.
         // document.getElementById('status').innerHTML = 'Please log ' +
         //   'into Facebook.';
         FB.login(function(response) {
             console.log(response);
         });
     }
}

function testAPI() {
    console.log('Welcome!  Fetching your information.... ');
    FB.api('/me', function(response) {
    console.log('Successful login for: ' + response.name);
    console.log(response);
    // Aqui ele loga no console a resposta vinda do facebook, mas vem apenas o ID e Nome do usuário..
});


}

** I tested on a server in the cloud and with other users besides me, and even then I only get the name and ID of the logged in user.

    
asked by anonymous 29.07.2015 / 05:00

1 answer

2

Are you requesting email permission at the time of login?

FB.login( function(response){
    // ...
}, {scope: 'email'});

Remembering that if the user leaves the email as private / empty, there is no way to get it. That is, you will not always be able to get the email from everyone who logs in.

[update]
I was looking around and saw that now you need to specify the field you want to receive, otherwise only the name and id is returned.

Example:

FB.login(function(){

  FB.api('/me', {fields: 'name, email'}, function(response){
    console.log(response);
  });

}, {scope: 'email'});
    
29.07.2015 / 22:28