facebook登录失败使用javascript sdk

问题描述 投票:0回答:1

我正在使用Facebook登录..但最近我在获取signin / signUp数据时遇到错误

这是我的代码

  <script>
    // This is called with the results from from FB.getLoginStatus().
    function statusChangeCallback(response) {
        console.log('statusChangeCallback');
        console.log(response);
        if (response.status === 'connected') {
            // Logged into your app and Facebook.
            testAPI();
        } else if (response.status === 'not_authorized') {
            fbLogin();
            // The person is not logged into your app or we are unable to tell.
            document.getElementById('status').innerHTML = 'Please log ' +'into this app.';
        }
        else {
            // The person is not logged into your app or we are unable to tell.
            document.getElementById('status').innerHTML = 'Please log ' +'into this app.';
        }
    }
    function checkLoginState() {
        FB.getLoginStatus(function (response) {
            statusChangeCallback(response);
        });
    }
    function fbLogin() {
        debugger;
        FB.login(function (response) {
            //if (response.authResponse) {
                console.log('Welcome!  Fetching your information.... ');
                FB.api('/me/?fields=picture,name,email', function (response) {
                    console.log(response);
                    console.log('Successful login for: ' + response.name);
                    document.getElementById('status').innerHTML =
                      'Thanks for logging in, ' + response.name + '!';
                });
            //} else {
            //    console.log('User cancelled login or did not fully authorize.');
            //}
        }, { auth_type: 'reauthenticate', auth_nonce: '{random-nonce}' });
    }
    window.fbAsyncInit = function () {
        FB.init({
            appId: '393788184007786',
            cookie: true,  // enable cookies to allow the server to access 
            // the session
            xfbml: true,  // parse social plugins on this page
            version: 'v3.2' // The Graph API version to use for the call
        });
    };
    // 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 = "https://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', { fields: 'name,email' }, function (response) {
            var info = response.id + '#' + response.name + '#' + response.email;
            console.log('Successful login for: ' + info);         
        });
    }
</script>

这是html中包含的按钮,用于登录

 <fb:login-button scope="public_profile,email" onlogin="checkLoginState();">
                                </fb:login-button>

getLoginState()的响应是:

{ authResponse: undefined, status: "not_authorized" }

这个错误显示enter image description here

我在Facebook应用程序中收到一条消息称“我们已经限制此应用程序违反Facebook平台政策”

有什么建议可以解决这个问题吗?!!

facebook-javascript-sdk
1个回答
0
投票

括号只是占位符,您必须删除它们:

FB.init({
    appId: '393788184007786',
    cookie: true, 
    xfbml: true,  
    version: 'v3.2' 
});
© www.soinside.com 2019 - 2024. All rights reserved.