Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Graph API v2.4 not returning extended user data

I'm developing an app that uses the Facebook Graph API to implement FB auth integration. As part of this, we fetch the user's email, first_name, and last_name from Facebook so we can either match the email address with an existing user in our database, or create a new user failing that.

In the Graph version 2.3 we could easily get this information with the following request, which you can test-run in the Graph API Explorer, assuming that we provided an access token having the permissions user_about_me and email:

Request: https://graph.facebook.com/v2.4/10154900171335022
Response: 
{
  "id": "123456",
  "email": "[email protected]",
  "first_name": "Buckeroo",
  "gender": "male",
  "last_name": "Banzai",
  "link": "https://www.facebook.com/app_scoped_user_id/123456/",
  "locale": "en_US",
  "name": "Buckeroo Banzai",
  "timezone": -4,
  "updated_time": "2015-06-06T07:21:23+0000",
  "verified": true
}

But when I switch to API v2.4 and try the same request, even when I enable all permissions, I get the following useless response:

{
  "name": "Topher Hunt",
  "id": "10154900171335022"
}

This doesn't match FB's API docs, which suggest that the full data (including email) should still be returned as it was in v2.3.

Has anyone successfully found a way to get a user's email address when using FB Graph v2.4? Any workarounds? Maybe I should just hold off on upgrading?

Thanks in advance!

like image 926
Topher Hunt Avatar asked Nov 22 '25 11:11

Topher Hunt


1 Answers

You should pass the 'fields' parameter with the relevant keyword of permissions. Please note, since the release of Graph API version 2.2 and above, users can deny the permission for a specific data field.

In addition to it, if the user has registered with a phone number then the email field will be returned as NULL.

To access email and about me of an user via HTTP, here is an example:

https://graph.facebook.com/v2.4/10154900171335022?fields=email,about

An example in Javascript.

     FB.login(function(response) {
               if(response.authResponse) { //If the user grants permission
                         FB.api('/me?fields=email,about', function(response) {
                           console.log(response.email);
                           console.log(reponse.about);
                         });
               } else {
                                // User cancelled login or did not fully authorize.
               }
    }, {
        scope: 'email,user_about_me'
    );
like image 66
Nishant Ghodke Avatar answered Nov 25 '25 11:11

Nishant Ghodke