Facebook登录流返回状态”;未知”;


Facebook Login Flow Returning Status "unknown"

所以,我最近创建了一个FB,它对所有用户都可用,据我所知,它不是沙箱模式。我使用了FB Developers网站文档中提供的示例代码,并将其放置在localhost上。"应用程序域"answers"网站URL"的设置都是正确的。因此,即使当我登录FB时,在Chrome的JS控制台中,它也会读取statusChangeCallback splash.php:60 Object {status: "unknown", authResponse: null}

我使用了以下代码

<script>
    // This is called with the results from from FB.getLoginStatus().
    function statusChangeCallback(response) {
        console.log('statusChangeCallback');
        console.log(response);
        if(response.status === 'connected') {
            testAPI();
        } else if(response.status === 'not_authorized') {
            document.getElementById('status').innerHTML = 'Please log ' + 'into this app.';
        } else {
            document.getElementById('status').innerHTML = 'Please log ' + 'into Facebook.';
        }
    }
    // This function is called when someone finishes with the Login
    // Button.  See the onlogin handler attached to it in the sample
    // code below.
    function checkLoginState() {
        FB.getLoginStatus(function(response) {
            statusChangeCallback(response);
        });
    }
    window.fbAsyncInit = function() {
        FB.init({
            appId: "I'm not dumb",
            //cookie: true,  
            status: true,
            xfbml: true,  
            oauth: true,
            version: 'v2.1' 
        });
        FB.getLoginStatus(function(response) {
            alert(response);
            if(response.status === 'connected') {
            if(response.authResponse != 'undefined') {
                    window.location = '<?php echo $base_url; ?>register';
                        }
            } else if(response.status === 'not_authorized') {
                        // it means we have a user but he hasn't granted any permissions to our app
                        // we're going to redirect him to the permission page
            } else {
                        //the user is not logged in, as you already have a login button you don't have to do nothing  
            }
        });
        FB.Event.subscribe('auth.login', function(response) {
            window.location = '<?php echo $base_url; ?>register';
        });
        FB.getLoginStatus(function(response) {
            statusChangeCallback(response);
        });
    };
    // Load the SDK asynchronously
    (function(d, s, id) {
        var js, fjs = d.getElementsByTagName(s)[0];
        if (d.getElementById(id)) return;
        js = d.createElement(s); js.id = id;
        js.src = "//connect.facebook.net/en_US/sdk.js";
        fjs.parentNode.insertBefore(js, fjs);
    } (document, 'script', 'facebook-jssdk'));
    // Here we run a very simple test of the Graph API after login is
    // successful.  See statusChangeCallback() for when this call is made.
    function testAPI() {
        console.log('Welcome!  Fetching your information.... ');
        FB.api('/me', function(response) {
        console.log('Successful login for: ' + response);
        document.getElementById('status').innerHTML = 'Thanks for logging in, ' + response + '!';
    });
    }
</script>
<fb:login-button scope="" onlogin="checkLoginState();"></fb:login-button>
<div id="status"></div>

我完全不知道为什么会发生这种情况,而且我以前从未遇到过这个问题。

我看过你的代码,

您已经编辑了js代码。

用你可以在下面的链接中找到的代码恢复你当前的js代码

https://developers.facebook.com/docs/facebook-login/login-flow-for-web/v2.1