I am developing a facebook app and I seem to have got stuck on an issue.
I am trying to assign the username to a variable by calling the below code, but the variable is returning null.
var current_user ='';
var arUser = FB.Connect.get_loggedInUser();
FB.Facebook.apiClient.users_getInfo(arUser, ["name"],
function (user, exec)
{ //alert(user[0].name); - this works!!
current_user = user[0].name;
});
alert(current_user); // this returns null :(
I get a value if I do an alert(user[0].name) within the function. I get a feeling that I need to wait for the response from execution of users_getInfo() before using the current_user variable, but not sure how..
Help much appreciated.