I have 3 javascript methods.
isLogin();
login();
reply();
when I’ll execute the reply method then first of all it should check that user is Login or not. If user is login then execute the reply method. If user is not login then execute it first and then execute reply method.
These are all Facebook Javascript SDK methods which are asynchronous. Therefore they don’t return a value.
if for instance these are not async methods then these can return value, on which I can take decesion like this.
function isLogin(){
if(user.islogin()){
return true
}
else{
return false;
}
function login(){
if(user.hasLogin()){
return true;
}
else{
return false;
}
function reply(){
if(!isLogin(){ //User is not login
if(login()){ //Login User
//user has login. now reply
sendText(); //any statement which will reply
}
}
}
Please help
Thanks
I don’t have experience with the Facebook JavaScript API, but from looking over their documentation briefly, the FB.getLoginStatus and FB.login methods do in fact return values.
Asynchronous methods can return values, they’re just performed in a “non-blocking” manner (the main program flow doesn’t halt to wait for them to complete). That’s what JavaScript “callback” functions are used for. Your script can continue doing other things after making the API request, and the callback function will get fired when the API returns it’s response.
The inner function (starting with function(response)) is the callback function, which will fire when the Facebook API returns it’s response to your script.
Calling the FB.login method will pop up a login window to the user. Your page will continue functioning while this window is open (as it is asynchronous to your program), and the FB.login callback function will fire once the user has either logged in or cancelled the login process.
For more explanation of how to use the Facebook JavaScript API methods, it’s always useful to read the documentation.