FB.getLoginStatus returns status unknown

前端 未结 10 1193
不思量自难忘°
不思量自难忘° 2020-12-05 14:20

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

         


        
相关标签:
10条回答
  • 2020-12-05 14:46

    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).

    0 讨论(0)
  • 2020-12-05 14:50

    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!
          }
       });
    }
    
    0 讨论(0)
  • 2020-12-05 14:51

    I had the same issue in IE. Flimzy's answer got me thinking. I tried running IE as administrator and it worked.

    0 讨论(0)
  • 2020-12-05 14:52

    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
    0 讨论(0)
  • 2020-12-05 14:56

    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;';
    }
    
    0 讨论(0)
  • 2020-12-05 15:02

    I had the same problem, I fixed this by clearing all cache and cookies.

    0 讨论(0)
提交回复
热议问题