Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook JS SDK's FB.api('/me') method doesn't return the fields I expect in Graph API v2.4+

I'm trying to get some basic information using Facebook api, but so far I only get the user's name and id. As in { name: "Juan Fuentes", id: "123456" }

I need to get mor einformation, like email, first name, last name and birthday

This is my js code

function facebookLogin() {   FB.login(function(response) {     var token = response.authResponse.accessToken;     var uid = response.authResponse.userID;     if (response.authResponse) {       FB.api('/me', 'get', { access_token: token }, function(response) {         console.log(response);       });        FB.api('/'+uid, 'get', { access_token: token }, function(response) {         console.log(response);       });     }   },   { scope: 'public_profile' }   ); } 

And this is the button that activates it

<a id="fb-login" href="#" onclick="facebookLogin()"></a> 
like image 656
Juan Fuentes Avatar asked Sep 15 '15 11:09

Juan Fuentes


People also ask

How do I get my Facebook API user ID?

The simplest way to get a copy of the User Profile object is to access the /me endpoint: FB. api('/me', function(response) { }); This will this will return the users name and an ID by default.

How do I find Facebook user data?

You can get user data by using the Facebook Graph API if the user has given their permission to share their data and your app has the appropriate permissions to receive this data. This topic shows you how to make a single request for data and how to have a batch of requests in a single request.


1 Answers

You need to manually specify each field since Graph API v2.4:

  • https://developers.facebook.com/docs/apps/changelog#v2_4
  • https://developers.facebook.com/docs/javascript/reference/FB.api

Declarative Fields
To try to improve performance on mobile networks, Nodes and Edges in v2.4 requires that you explicitly request the field(s) you need for your GET requests. For example, GET /v2.4/me/feed no longer includes likes and comments by default, but GET /v2.4/me/feed?fields=comments,likes will return the data. For more details see the docs on how to request specific fields.

E.g.

FB.api('/me', 'get', { access_token: token, fields: 'id,name,gender' }, function(response) {     console.log(response); }); 
like image 179
Tobi Avatar answered Sep 29 '22 08:09

Tobi