So I am using a function as such to get the access token of the already authenticated user that is currently on my website:
var token;
FB.getLoginStatus(
function(response){
if (response.session) {
alert(response.session.access_token);
//This correctly shows the access token. <-----GOOD
token = response.session.access_token;
}
else{
//Other stuff.
}
}
);
alert(token);
//This shows undefined. <------PROBLEM
The only way to know the access token it seems is to be within the anonymous function called within the call to FB.getLoginStatus.
I have determined that the problem is that the anonymous function inside of FB.getLoginStatus is not executed until the end of all other scripts on the page. Therefore, the variable "token" will not be set until everything is done executing, rendering it useless.
Is there a way then to extract the access token into a universally accessible variable? I don't want to have to write all my code which requires knowledge of the access token in a single anonymous function.