質問

placing a fb js sdk api login call in a function and returning it's response.

I am breaking down different features into functions and was wondering how I can return the response this facebook call generates to be used elsewhere.

function facebook_login()
{
    FB.login(function(response) {
       // handle the response
       console.log('in facebook_login function');
       console.dir(response.authResponse);
       return response;
    }, {scope: 'publish_actions', return_scopes: true});
}

var response_from_facebook_login_function = facebook_login();
役に立ちましたか?

解決

Ajax is async, so you need to use a callback function. Try this:

function facebook_login(call_back){
//etc
console.dir(response.authResponse);
call_back(response);
//etc

facebook_login(saveResponse);

function saveResponse(response){
    var response_from_facebook_login_function=response;
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top