I am trying to get the username for a particular user by giving the user id as a param to the FB.api method. But it just returns undefined. If i console.log within the FB.api method, i can see the result. Unable to figure out.
var something;
var friendName = FB.api('/{{ user id }}', function(give){ something = give.name; });
console.log(something);
The method is asynchronous, that means the answer to the server-side call is not yet there when your following line (logging to console) is carried out – and therefor the callback function has not been executed yet, so it hasn’t set the var something at that point.
You should familiarize yourself with the basics of asynchronous execution in javascript!