Facebook API登录getLoginStatus拒绝显示。 。 。 'X-Frame-Options''拒绝'v2.10

时间:2017-09-28 10:15:11

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

情况:用户加载页面并检查用户是否登录了Facebook。

问题:在功能 .getLoginStatus 之后(参见js)我得到了
错误消息:拒绝显示... https://www.facebook.com/connect/ping ...''X-Frame-Options'为'拒绝'

我有一个其他网站,我没有更改FB-Code,但已经无法使用了。

数据: v2.10

已检查: Firefox(失败),Chrome(失败),Edge(成功)

我希望有人可以帮助我。

按钮

<div id="fb-root">
    <div class="fb-login-button" data-max-rows="3" data-size="large" data-button-type="login_with" data-show-faces="false" data-auto-logout-link="false" data-use-continue-as="false" data-scope="public_profile,email"
        data-mislogin="<?php echo isset ( $_SESSION ['userData'] [0] ['logInStatus'] )?'true':'false';?>" data-fbappId="<?php echo $fb_appId;?>"></div>
</div>

Javascript代码类

/**
 * Facebook Login Handler
 */
var FBLoginHandler;

var isUserLog;
var isUserLoggedIn;

FBLoginHandler = new FBLoginHandler();

isUserLog = true;

FBLoginHandler.start();

function FBLoginHandler() {

    this.start = function() {

        var fb_graphVersion;
        var fb_appId;

        var fbLoginBt;

        fb_graphVersion = 'v2.10';
        fbLoginBt = $('.fb-login-button');

        if (fbLoginBt.length > 0) {

            fb_appId = fbLoginBt.attr('data-fbappId');
            isUserLoggedIn = fbLoginBt.attr('data-mislogin');

            if (isUserLoggedIn === 'false' || isUserLoggedIn === false) {

                window.fbAsyncInit = function() {
                    FB.init({
                        appId : fb_appId,
                        autoLogAppEvents : false,
                        xfbml : true,
                        version : fb_graphVersion
                    });

                    FB.AppEvents.logPageView();

                    FBLoginHandler.checkLoginState();
                }

                this.createLoginBt(fb_graphVersion,fb_appId);
            }
        };

        /*
         * This function is called when someone finishes with the Login Button. See the onlogin handler attached to it in the sample code below.
         */
        this.checkLoginState = function() {

            // Now that we've initialized the JavaScript SDK, we call
            // FB.getLoginStatus(). This function gets the state of the
            // person visiting this page and can return one of three states to
            // the callback you provide. They can be:
            //
            // 1. Logged into your app ('connected')
            // 2. Logged into Facebook, but not your app ('not_authorized')
            // 3. Not logged into Facebook and can't tell if they are logged into
            // your app or not.
            //
            // These three cases are handled in the callback function.
            FB.getLoginStatus(function(response) {
                FBLoginHandler.statusChangeCallback(response);
            });
        }

        /*
         * The response object is returned with a status field that lets the app know the current login status of the person. Full docs on the response object
         * can be found in the documentation for FB.getLoginStatus().
         */
        this.statusChangeCallback = function(response) {

            if (response.status === 'connected') {

                // Logged into your app and Facebook.
                FBLoginHandler.isFbLoginRight();
            } else if (response.status === 'not_authorized') {
                // The person is logged into Facebook, but not your app.

            } else {
                // The person is not logged into Facebook, so we're not sure if
                // they are logged into this app or not.

            }
        }

        /**
         * AJAX Meldung sobald der Benutzer sich in Facebook eingelogt hat.
         */
        this.isFbLoginRight = function() {

            $.get(domain_https_basicfull_www
                    + '/ajax/facebook/checkfblogin/?modus=x', function(result) {

                //0=Fehler bei der Anmeldung, 1=Anmeldung Erfolgreich-Seite wird neu geladen.
                var fbLoginResult = JSON.parse(result);

                switch (fbLoginResult.resultNr) {
                    case '0' :
                        swal({
                            title : LanguageBasic.getString('Error') + '!',
                            html : 'Facebook',
                            type : 'error'
                        })
                        break;
                    case '1' :
                        location.reload();
                        break;
                    default :
                        break;
                }
            });

        }
    }

    this.onLoginSubmit = function() {

        $(".fb-login-button").off("onlogin");

        $(".fb-login-button").on("onlogin", function(e) {

            FBLoginHandler.checkLoginState()

            return false;
        });
    }

    this.createLoginBt = function(fb_graphVersion,fb_appId) {

        (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#xfbml=1&version="+fb_graphVersion+"&appId="+fb_appId;
          fjs.parentNode.insertBefore(js, fjs);
        }(document, 'script', 'facebook-jssdk'));
    }
}

2 个答案:

答案 0 :(得分:0)

我发现了enter link description here

如果我检查用户是否登录但仍然存在问题但是如果用户单击自我,则可以登录fb按钮=)

答案 1 :(得分:0)

遇到同样的错误,最终对我有用的是将应用程序仪表板设置中的网站URL更改为我的开发URL。经过一段时间的封锁后,这个答案为我指明了正确的方向-https://stackoverflow.com/a/53325827/3787212