How to return a value from facebook javascript connect api fucntions
- by dezwald
I am trying to create wrapper functions on facebook javascript connect api methods.
My problem is that i can not return a value within the facebook api FB_RequireFeatures method.
i want my isFBConnected() function to return true or false based on if i'm logged into facebook or not.
What is happening is that when i return true it returns it to the child function, which makes sense however, my global "login" variable does not get set to true.
I've tried setting a timeout to wait until the facebook connect finishes executing and still no luck.
any help or other solutions are welcome!
my isFBConnected wrapper function is stated below:
function isFBConnected(){
var api_key = '<?=$this->apiKey?>';
var channel_path = '<?=$this->xdReceiver?>';
var host_url = '<?=$this->hostUrl?>';
var servicePathShort = '<?=$this->servicePathShort?>';
var login = false;
FB_RequireFeatures(["Api"], function(){
// Create an ApiClient object, passing app's API key and
// a site relative URL to xd_receiver.htm
FB.Facebook.init(api_key, channel_path);
var api = FB.Facebook.apiClient;
// If FB user session exists - load stats data
if(api.get_session()!=null){
if(api.get_session().uid!='' && api.get_session().uid!=undefined){
login = true;
alert(api.get_session().uid);
return true;
}
}
login = false;
return false;
});
return false;
}