0

我在获取已登录用户的登录状态时遇到问题。不会调用 getLoginStatus 函数。我想获取访问令牌以获取用户数据。我尝试使用自己的 APP-ID 和游戏 APP-ID (298553513572593)。上面你可以看到我的代码:

<body>
    <div id="fb-root"></div>
    <script type="text/javascript">
        // 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 = "http://connect.facebook.net/de_DE/all.js";
            js.src = "http://connect.facebook.net/de_DE/all.js#xfbml=1&appId=APP_ID";
            fjs.parentNode.insertBefore(js, fjs);
        }
        (document, 'script', 'facebook-jssdk')
    );

        function login() {
            FB.login(function(response) {
                if (response.authResponse) {
                    // connected
                } else {
                    // cancelled
                }
            });
        }

        window.fbAsyncInit = function() {
            // init the FB JS SDK
            FB.init({
                appId      : 'APP_ID',                          
                status     : true,                                      
                cookie     : true,
                xfbml      : true 
            });

            // Additional initialization code such as adding Event Listeners goes here                      
            FB.getLoginStatus(function(response) {
                alert(response);
                if (response.status === 'connected') {
                    // connected
                    var uid = response.authResponse.userID;
                    var accessToken = response.authResponse.accessToken;
                } else if (response.status === 'not_authorized') {
                    // not_authorized
                    login();
                } else {
                    // not_logged_in
                    login();
                }
            });
        };
    </script>
    <div>
        <fb:login-button show-faces="true" width="200" max-rows="1"></fb:login-button>
    </div>
</body>

Html-Tag 具有属性xmlns:fb="http://ogp.me/ns/fb#"

4

0 回答 0