Use FB.api to store global javascript variable

I want to store the user id from FB.api into a global variable that I can use in other functions… how do I do this? I have the following code but it doesnt work…

var fbuserId;

    function getFbid() {


        FB.api('/me', function(response) {
           fbuserId =  response.id;
        });

        return fbuserId;
    }

params.fbuid = getFbid();   // calling the getFbid() to return the variable, but returns nothing

Hi,

I have no idea what “Fb.api” is; however…

  1. have you tried placing alert messages in your functions to see if you are getting in, what values are being sent, received?

FB.api(‘/me’, function(response) {

FB.api(“\/me”,…

FB.api is a method for Facebook Graph api… but the problem I guess is more related to storing variables from within functions

I have tried to do the alert inside the function and it outputs the correct data, but when I try to store the data in the global variable fbuserId for some reason it aint working

Hi,
you can’t do like that because FB.api is asyn
so you never know when uid is available
take a look
http://stackoverflow.com/questions/7652558/how-do-i-use-an-fb-apijs-sdk-response-outside-of-the-callback-function
Bye