fb.getloginstatus在注销后未启动

fb.getloginstatus not firing after logout

本文关键字:启动 注销 getloginstatus fb      更新时间:2023-09-26

我长期使用Facebook OAuth。

应用程序没有得到getLoginStatus总是得到未知的状态。最近我遇到了这个问题。

工作正常,直到我点击注销按钮。一旦我点击注销按钮,我将面临此登录
问题

这是我的代码

<html>
<head>
</head>
<body>
    <div id="fb-root">
        <br>
        <br>
        <button onclick="status();">Login</button>
        <br>
        <br>
        <button onclick="logout();">Log Out</button>
    </div>
    <div id="fb-root"></div>
    <script>
    window.fbAsyncInit = function() {
        FB.init({
            appId: '137827113065883',
            status: true,
            cookie: true,
            xfbml: true,
        });
        FB.Event.subscribe('auth.login', function(response) {
            alert('logged in');
        });
        FB.Event.subscribe('auth.logout', function(response) {
            alert('logged out');
        });
    };
    function logout() {
        FB.logout(function(response) {
            console.log('out ' + JSON.stringify(response));
        });
    }
    function status() {
        FB.getLoginStatus(function(response) {
            console.log(JSON.stringify(response))
            if (response.status === 'connected') {
                var accessToken = response.authResponse.accessToken;
                console.log(accessToken);
            } else if (response.status === 'not_authorized') {
                var redirect_uri = window.location.protocol + "//" + window.location.host + window.location.pathname;
                window.location = "https://facebook.com/dialog/oauth?redirect_uri=" + redirect_uri + "&client_id=137827113065883&response_type=token";
            } else {
                var redirect_uri = window.location.protocol + "//" + window.location.host + window.location.pathname;
                window.location = "https://facebook.com/dialog/oauth?redirect_uri=" + redirect_uri + "&client_id=137827113065883&response_type=token";
            }
        }, true);
    }
    //Load the SDK Asynchronous
    (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));
    </script>
    </body>
</html>

谢谢大家,我找到了解决这个问题的方法

通过在注销时删除所有cookie点击。

我用这个删除cookie

document.cookie.split(";").forEach(function(c) {
                document.cookie = c.replace(/^ +/, "").replace(/=.*/, "=;expires=" + new Date().toUTCString() + ";domain=.example.com;path=/");
            });