facebook api not returning email

14,474

Solution 1

FB.api('/me?fields=email,name', function(response) { /* stuff here */ });

Try adding your return fields to your request.

Solution 2

I know this is old question however if someone still seraching for answers then following workaround worked for me.

You need to add email in scope scope="public_profile,email".

<fb:login-button  scope="public_profile,email" autologoutlink="false" onlogin="OnRequestPermission();"></fb:login-button>

Solution 3

A possible cause is that the user did not validate the email. Try with another user with validated email to make sure this is not the problem.

See also this answer

Solution 4

If you set all code correctly and still don't get an email from API. The user probably doesn't have an email bound to the account or the email not confirmed by the user.

Share:
14,474
user232343
Author by

user232343

Updated on June 12, 2022

Comments

  • user232343
    user232343 almost 2 years

    I am trying to return user email address using facebook api. Few days ago it was working fine, but today stopped working, and don't know why.

    So first I get access token:

    FB.login(response => {
        if (response.authResponse) {
          resolve(response.authResponse.accessToken);
        } else {
          reject({
            error: 'User cancelled login or did not fully authorize.'
          });
        }
      }, {
        scope: 'public_profile,email'
      });
    

    then I try to get user data

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

    but I only get data for first_name and last_name. There is no email.

    Also when I ask for permissions, it gives me email as granted, but as I said, email is not returned.

    FB.api('/me/permissions', function(response) {
      console.log(response);
    });
    

    Does anyone knows what can be the problem?

    BTW: I am using API v2.4.