How to return a value from facebook javascript connect api fucntions

Posted by dezwald on Stack Overflow See other posts from Stack Overflow or by dezwald
Published on 2010-03-29T23:52:38Z Indexed on 2010/03/29 23:53 UTC
Read the original article Hit count: 252

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;

}

© Stack Overflow or respective owner

Related posts about facebook-connect

Related posts about facebook-api