php - Facebook 登录流程返回状态 "unknown"

标签 php facebook facebook-graph-api

因此,我最近创建了一个可供所有用户使用的 FB,据我所知,该 FB 未处于沙盒模式。我使用了 FB Developers 网站上的文档中提供的示例代码并将其放在本地主机上。 “App Domains”和“Site URL”的设置都是正确的。因此,即使我登录 FB,在登录后,在 Chrome 的 JS 控制台中,它也会显示 statusChangeCallback splash.php:60 对象 {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

关于php - Facebook 登录流程返回状态 "unknown",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26307669/

相关文章:

php - 以特定间隔合并数组

php - L_ERRORCODE0 : 10401 returned by DoReferenceTransaction

facebook - FB 选项卡应用程序在新窗口中打开,而不是在 iframe 中打开 [Firefox 6]

facebook - 将视频字幕文件上传到 Facebook?

facebook - 共享缓存超时

javascript - 如何使用 javascript 将用户 friend 连接的 facebook graph api 响应存储到变量或数组以便稍后使用

ios - 使用 Swift 创建 Facebook Open Graph 对象

php - 什么是更快的 : in_array or isset?

ios - 检查用户是否修改了应用程序的 Facebook 权限

PHP 检查数组是否相同?