I am using fb login connect in my demo site :
I used this code:
window.fbAsyncInit = function() {
try{
FB.init({
apiKey: '<MY APP KEY>',
channelUrl : 'www.google.com'
});
FB.getLoginStatus(function(response){
loginHandler();
});
}catch(error){}
};
function loginHandler(success,fail)
{
try{
if(success){
alert('i am if');
FB.api('/me', function(response,fail) {
alert("first name == " + response.first_name + "\n ln === " + response.last_name);
});
}
}catch(error){}
}
$('#login').bind('click', function(response) {
try{
FB.login(loginHandler, {scope: 'email,user_likes'});
}catch(error){}
});
$('#logout').bind('click', function() {
try{
FB.logout(function(response){});
}catch(error){}
});
Now my problem is that alert(‘i am if’); is showing every time whether I passed correct credentials to facebook or not and alert(“first name == ” + response.first_name + “\n ln === ” + response.last_name); shows undefined when user passes wrong credentials and shows correct info when user comes back passing correct info.
one possible option is to check like if(response.first_name!=undefined){blah blah....} but is it correct method of checking the authentication?
Please shed some light….
Try something like this:
//for login $("#login").bind("click", function(e) { var fbScope = "email,user_likes"; FB.login(function(response) { if(response.status == "connected"){ console.log("Logged in"); } },{scope: fbScope}); }); //for checking logged in status FB.getLoginStatus(function(response){ if (response.authResponse) { var accessToken = response.authResponse.accessToken; FB.api('/me', function(response) { console.log('I m still loggedin'); }); } }); //for logout $("#logout").live("click", function(e) { FB.getLoginStatus(function(response){ if(response.status == "connected"){ FB.logout(function(response) { console.log("I m logged out now"); }); } else { console.log("Not Logged logged in"); } }); });