1

Can't Get Response.email from facebook API v2.5 even email is green in App Reviews. I used this basic FB.api(), even with SCOPE it doesn't return EMAIL

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

4 Answers4

1

The proper way to ask for additional fields (other than id and name) is this one:

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

Of course, make sure you have added the email permission in the scope:

FB.login(function(response) {
    if (response.authResponse) {

    }
}, {scope: 'email'});

Additional information.

Btw, you can test API calls here.

itzmebibin
  • 9,199
  • 8
  • 48
  • 62
andyrandy
  • 72,880
  • 8
  • 113
  • 130
  • i still cant get the email of the logged in user. do i have to make a request to facebook for the permission? but the email is already approved im my app – Nikko Joson May 11 '16 at 03:33
  • approved does not mean that the user authorized it. see FB.login. and the email address has to be approved in the user account too. – andyrandy May 11 '16 at 07:43
  • i used the code you have given and now it only returns me the user ID, – Nikko Joson May 18 '16 at 01:17
  • then you did not authorize correctly, or your email is not approved. try fields: 'email, name' if you need the name too. and read about declarative fields in the changelog. – andyrandy May 18 '16 at 07:50
  • mybad, nothing is wrong with the code, I just did a reset with the permissions on the app. – Nikko Joson Oct 24 '19 at 11:57
0

First of all make sure that FB.login() is called with scope: email so that the token will have the permission to access the user's email.

Then, you should mention the field email explicitly while calling /me since by default it will return id and name only.

  FB.api('/me?fields=email', function(response) {
      console.log(response);
  });
Sahil Mittal
  • 20,697
  • 12
  • 65
  • 90
0

Make sure you define "email" scope while login, then you could get it when you ask graph.facebook.com:

$url = 'https://www.facebook.com/dialog/oauth';
$params = array(
    'client_id' => $this->strategy['app_id'],
    'redirect_uri' => $this->strategy['redirect_uri'],
    'scope' => 'email',
);
0

mybad, nothing is wrong with the code, I just did a reset with the permissions on the app.