When calling FB.getLoginStatus using a valid Facebook App the response status is always unknown. Exact response is {authResponse: undefined, status: \"unknown\"}.
You have to test it from the live domain (which you provided in the app).
I had the same problem when testing locally (using local domain).
When I checked, the status is showing "not_authorized"
and that's fine, since I've not authorized the app yet.
To complete the flow, you should add the FB.login
whenever user id is not authorized or not logged-in to facebook:
window.fbAsyncInit = function(){
FB.init({ appId:'{APP-ID}', status:true, cookie:true, xfbml:true});
FB.getLoginStatus(function(response){
if (response.status === 'connected') {
//proceed
} else if (response.status === 'not_authorized') {
login();
} else {
login();
}
});
};
function login(){
FB.login(function(response) {
if (response.authResponse) {
// proceed
} else {
// not auth / cancelled the login!
}
});
}
I had the same issue in IE. Flimzy's answer got me thinking. I tried running IE as administrator and it worked.
This was happening for me in Chrome, and was because Chrome was configured to block third-party cookies and data.
Once I made that configuration change, FaceBook is able to log me into my app without a problem.
I too faced this problem in Chrome. However, in Firefox it worked as expected with the status returned as connected
when the user had logged in previously.
I found a clue about this from an answer to the similar question here.
The root cause of this issue is, on FB.logout()
, Chrome is not removing the cookie fblo_<your-app-id>
which is somehow affecting FB.getLoginStatus()
function to return unknown
Fix: On calling FB.logout()
, you may programmatically delete the cookie fblo_<your-app-id>
FB.logout(function(response) {
deleteCookie("fblo_" + fbAppId); // fblo_yourFBAppId. example: fblo_444499089231295
});
function deleteCookie(name) {
document.cookie = name +'=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
}
I had the same problem, I fixed this by clearing all cache and cookies.