Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FB.getLoginStatus returns status unknown

When calling FB.getLoginStatus using a valid Facebook App the response status is always unknown. Exact response is {authResponse: undefined, status: "unknown"}.

<html> <body>     <div id="fb-root"></div>      <script>     window.fbAsyncInit = function(){         FB.init({ appId:'1484134468466778', status:true,  cookie:true, xfbml:true});         FB.getLoginStatus(function(response){         console.log(response);         });     };      (function(d){         var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}         js = d.createElement('script'); js.id = id; js.async = true;         js.src = "//connect.facebook.net/en_US/all.js";         d.getElementsByTagName('head')[0].appendChild(js);     }(document));     </script> </body> </html> 


Example URL: http://media.tuentifotos.com/simple_test.html


Here a screenshot of the Facebook App Settings. Facebook App Settings

like image 902
Diego Cerdan Puyol Avatar asked Apr 06 '14 03:04

Diego Cerdan Puyol


People also ask

What is the response status of getloginstatus in Facebook app?

When calling FB.getLoginStatus using a valid Facebook App the response status is always unknown. Exact response is {authResponse: undefined, status: "unknown"}.

How does Facebook get login status data from the SDK?

The first time in the current browser session that FB.getLoginStatus is called, or the JS SDK is init'd with status: true, the response object will be cached by the SDK. Subsequent calls to FB.getLoginStatus will return data from this cached response.

How can I check the status of a user on Facebook?

In this case, rather than calling FB.getLoginStatus explicitly, it is possible to check the user's status by setting status: true when you call FB.init. To receive the response of this call, you must subscribe to the auth.statusChange event.

What happens if I set Facebook login status on every page?

If you call FB.getLoginStatus on every page load, be careful not to set this parameter for each as it will significantly increase the number of requests to Facebook's servers, and thus decrease the performance of your application.


2 Answers

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.

  • Chrome Settings
  • Show advanced settings...
  • Privacy
  • Content settings...
  • uncheck Block third-party cookies and site data
like image 186
Flimzy Avatar answered Sep 21 '22 06:09

Flimzy


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;'; } 
like image 35
Nagesh Andani Avatar answered Sep 18 '22 06:09

Nagesh Andani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!