开发者

How to return a value from Facebook Javascript connect api functions

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;

}


Well, first, you know that the FB_RequireFeatures function's second parameter is a callback function, which means that your IsFBConnected function will always return false, right? Do you really need the FB_RequireFeatures function? Can you just call FB.init directly instead?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜