为什么FB.getLoginStatus()总是返回response.status“unknown”?

时间:2013-12-22 11:43:02

标签: facebook facebook-graph-api facebook-javascript-sdk

为什么即使我已经对我的应用进行了身份验证,它仍会在FB.getLoginStatus()的响应中返回“unknown”?

我有这段代码:

<html>
<head></head>
<body>
<div id="fb-root"></div>
<script>
    window.fbAsyncInit = function() {
        FB.init({
            appId      : '###',
            status     : true, // check login status
            cookie     : true, // enable cookies to allow the server to access the session
            xfbml      : true  // parse XFBML
        });

        //check status...
        FB.getLoginStatus(function(response) {
            console.log('The status of the session is: ' + response.status);
        });
    };

    // Load the SDK asynchronously
    (function(d){
        var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
        if (d.getElementById(id)) {return;}
        js = d.createElement('script'); js.id = id; js.async = true;
        js.src = "//connect.facebook.net/en_US/all.js";
        ref.parentNode.insertBefore(js, ref);
    }(document));

    // Here we run a very simple test of the Graph API after login is successful. 
    // This testAPI() function is only called in those cases. 
    function testAPI() {
        console.log('Welcome!  Fetching your information.... ');
        FB.api('/me', function(response) {
            console.log('Good to see you, ' + response.name + '.');
        });
    }
</script>
<a href="javascript:FB.login();">Login</a>
</body>
</html>

我期待这些数据的结果:

{
  status: "connected",
  authResponse: {
    userID: "###",
    signedRequest: "###",
    expiresIn: "###",
    accessToken: "###"
  }
}

有没有其他方法可以在FB JS SDK中获取用户的登录状态?我已经尝试过FB.Event.subscribe()但仍然是一样的。什么都没发生.. -_-

1 个答案:

答案 0 :(得分:0)

不要使用“http”作为你的开发主机

只需使用 https 而不是 http 就可以了!

相关问题