I can not get the user's name Facebook api js


I have this code to try getting the user's name

FB.api('/me', function(response) {
    console.log('Successful login for: ' + response.name);

but the answer that the console gives me is:


Successful login for: undefined

without the .name the answer is:


Successful login for: [object Object]

that is, the response.name returns to me as undefined ... I have already verified that the user is connected and everything but I could not get their basic information, there was another way that I asked for a token that could not be obtained but anyway this method should work because it is the same example that gives me the documentation of the Facebook api.

asked by Cristofer Fuentes 30.06.2016 в 21:56

1 answer

FB.api('/me?fields=id,name,email,permissions', function(response) {
    console.log('Bienvenido, ' + response.name + '.');
    alert('Bienvenido, ' + response.name + '.');

Reference and for more information:

FB - Public Profile

Graph API User

answered by 30.06.2016 / 23:14