Facebook JS SDK's FB.api('/me') method doesn't return the fields I expect in Graph API v2.4+
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);
});
Facebook graph api not returning all public fields
https://developers.facebook.com/docs/graph-api/using-graph-api#reading
Check out the section "Choosing Fields", you have to ask for fields you want to get, else you will only get some default ones.
Unable to get the email and first_name from Facebook JavaScript SDK
Fb.api( '/me?fields=id,email,first_name,last_name', function(response) { console.log('Successful login for: ' + response.name); console.log(JSON.stringify(response)); });
Also remember that some fields require user permissions also.
And to run on localhost you need to add localhost in your app setting's app domain.
Good luck
Unable to access user's email by using facebook login
You must specify each field you want to have returned. Have a look at the answer at
- Facebook JS SDK's FB.api('/me') method doesn't return the fields i expect in Graph API v2.4+
facebook connect does not return email address
FB.api('/me', {fields: 'name,email'}, function(response) {
user_email = response.email; //get user email
console.log(response);
});
It´s called "Declarative Fields", see changelog: https://developers.facebook.com/docs/apps/changelog#v2_4
Javascript facebook login get email
Replace
FB.api('/me', function(response) { } )
by
FB.api('/me?fields=id,email,name', function(response) { } )
and make sure you are using scope email on the login function, like this
FB.login(function(response) {
// handle the response
}, {scope: 'email,user_likes'});
See docs for more details
How can I retrieve email via Facebook Graph API v2.8?
FB.api('/me', {fields: 'name,email'}, (response) => {
console.log(response);
});
It is called "Declarative Fields" and came with v2.4 of the Graph API: https://developers.facebook.com/docs/apps/changelog#v2_4
How to get person's address using Facebook Javascript SDK?
FB.api('/me')
Will give you the user's id without requiring any special permissions.
You can't get address as such, you can get location
using the user_location
permission. Then you'll be able to get it via the same /me
method.
Facebook Developers doc:
https://developers.facebook.com/docs/reference/api/user/
Related Topics
Loop Through an Array in JavaScript
Ways to Deal With #Document Under Iframe
How to Encode a String to Base64 in JavaScript
Direct Vs. Delegated - Jquery .On()
Deleting Array Elements in JavaScript - Delete VS Splice
Formatting a Number With Exactly Two Decimals in JavaScript
Location of Parenthesis For Auto-Executing Anonymous JavaScript Functions
Is There a "Null Coalescing" Operator in JavaScript
Question Mark and Colon in JavaScript
Remove Duplicate Values from Js Array
How to Access the Contents of an Iframe With JavaScript/Jquery
What Is the 'New' Keyword in JavaScript
What Does "This" Refer to in Arrow Functions in Es6
JavaScript Equivalent of Python'S Zip Function
How to Make Setinterval Also Work When a Tab Is Inactive in Chrome
Addeventlistener Calls the Function Without Me Even Asking It To