0

我正在使用 Facebooks 文档中的登录代码:

这在桌面浏览器中运行良好,但在平板电脑上,整个站点会尝试重定向到https://m.facebook.com...URL,而不是显示权限弹出。它重定向到的页面只显示错误。弹出窗口不能在 Facebook Javascript SDK 中工作吗?

<div id="fb-root"></div>
<script type="text/javascript">

    var likesPage = false;
    var addisPageId = 'XXXXXX';


    window.fbAsyncInit = function () {
        // init the FB JS SDK
        FB.init({
            appId: 'XXXXXXX',                        // App ID from the app dashboard
            channelUrl: '/channel.html', // Channel file for x-domain comms
            status: true,                                 // Check Facebook Login status
            xfbml: true                                  // Look for social plugins on the page
        });

        // Additional initialization code such as adding Event Listeners goes here
    };

    // 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_gb/all.js";
        fjs.parentNode.insertBefore(js, fjs);
    } (document, 'script', 'facebook-jssdk'));
    function callLogin() {
        FB.login(function (response) {
            var access_token = FB.getAuthResponse()['accessToken'];
            $("#at").val(access_token);

            if (response.authResponse) {
                FB.api('/me/likes?fields=id', function (response) {

                    for (var i = 0; i < response.data.length; i++) {
                        if (response.data[i].id == addisPageId) {
                            likesPage = true;
                            break;
                        }
                    }
                    if (likesPage) {
                        FB.api('/me', function (userInfo) {
                            document.getElementById("email").value = userInfo.email;
                            document.getElementById("fbId").value = userInfo.id;
                            document.getElementById("fbform").submit();
                        });
                    } else {
                        document.getElementById("dontLikePage").style.display = "inline";
                    }
                });
            } else {
                window.parent.location = "https://www.facebook.com/XXXX";
            }
        }, { scope: 'user_likes,email,publish_stream' });

    }
</script>
4

1 回答 1

0

这个问题有一段时间了。我通过使用您的 facebook 登录按钮https://developers.facebook.com/docs/reference/plugins/login/解决了这个问题,这在平板电脑上运行良好,但由于您描述的问题,在 javascript 中使用 fb.login 只是错误。

于 2013-11-08T16:32:01.020 回答