Login with facebook api does not return user email

Asked

Viewed 2,823 times

4

Greetings guys,

I spent hours and hours researching some solution to this problem, including here on the site, but I couldn’t find anything to help me.

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

Thanks for your cooperation.

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

Oops, the code I’m using to test is the same as available 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 mine, and even then I get only the name and ID of the logged in user.

  • 1

    Can you post the code too? Sometimes it can be because you are localhost, try going up to the server and redo the test.

  • Oops, I changed the question and includes the code used

1 answer

3


You are requesting email permission at login time?

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

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

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

Example:

FB.login(function(){

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

}, {scope: 'email'});
  • Yes, I put the request through email and public profile. including the popup that opens requesting authorization, it shows that the app is asking to access the email and public profile

  • I updated the answer, that must be it.

  • Expensive ball show, that was it.. Thank you very much.. They should leave this information with easier access heuheueh

Browser other questions tagged

You are not signed in. Login or sign up in order to post.