0

I'm playing around with the Facebook Javascript SDK to allow the end user to signup to my website via facebook, I've been following a tutorial online and so far so good, however I need to retrieve the user's email address, unfortunately response.email is always undefined, this is my code so far:

   FB.login(function (response) {
        if (response.authResponse) {
            console.log('Welcome!  Fetching your information.... ');
            FB.api('/me?fields=email,name', function (response) {
                console.log(response);
                console.log('Good to see you, ' + response.name + '.');
            });
        } else {
            console.log('User cancelled login or did not fully authorize.');
        }
    });

Which is executed off a button click, Now when I log response I have the userId and my name which is correct, after doing some googling some people have suggested I check that my email address on my facebook profile is set to public so I've gone through my profile set the relevant section to public but yet I still can't return the email address?

Any help would be appreciated.

Update

I've gone through and asked for permissions via the facebook SDK outlining the email address, this is now the response back from facebook after logging in again:

enter image description here

Yet when I drill down into email I see this:

enter image description here

Not the actual email address?

Amruth
  • 5,792
  • 2
  • 28
  • 41
Code Ratchet
  • 5,758
  • 18
  • 77
  • 141
  • I think you are using the public object that only contains first_name, last_name, gender etc.. but not email -> https://developers.facebook.com/docs/facebook-login/permissions#reference-email – Velimir Tchatchevsky Mar 30 '16 at 11:14
  • @VelimirTchatchevsky I've just added an update to my question, detailing where I am now with the issue. – Code Ratchet Mar 30 '16 at 11:20
  • I found a similar question - http://stackoverflow.com/questions/17532476/facebook-email-field-return-null-even-if-the-email-permission-is-set-and-acce check out if your email is confirmed and also you can use the username@facebook.com to send emails I think – Velimir Tchatchevsky Mar 30 '16 at 11:33
  • 1
    @VelimirTchatchevsky: The `username@facebook.com` addresses are deprecated, Facebook will not put stuff send there in inbox any more, but only forward it to the user’s external email address. Plus, since API v2.0, you won’t _get_ the `username` any more. – CBroe Mar 30 '16 at 12:03

0 Answers0