【问题标题】:FB redirect issue with white page in iOS chromeiOS chrome中白页的FB重定向问题
【发布时间】:2013-04-01 14:45:24
【问题描述】:

当我按下登录按钮时,我会进入 facebook 页面,我必须在其中授予使用我的 facebook 帐户的权限。

在我给予许可后,它会重定向到https://www.facebook.com/dialog/permissions.request 并显示一个空白页面。在 Android 上调用“window.FB.login”回调(参见下面的代码),我可以在其中获取信息并重定向用户,但在 Windows Phone 上它只显示该空白页面。当我转到我的 Facebook 页面时,我的网站已在应用列表中注册。所以注册确实工作正常。

【问题讨论】:

    标签: ios facebook google-chrome


    【解决方案1】:

    这个错误是由于facebook js文件的不安全加载引起的。

    要将 Facebook 应用程序集成到您的应用程序中,您必须按照 Facebook 应用程序文档中说明的步骤操作。

        var fbApi = {
          init: function () {
          $.getScript(document.location.protocol + '//connect.facebook.net/en_US/all.js', function () {
            if (window.FB) {
                window.FB.init({
                    appId: MY_APP_ID,
                    status: true,
                    cookie: true,
                    xfbml: false,
                    oauth: true,
                    channelUrl: 'http://www.yourdomain.com/channel.html'
                });
    
            }
        });
        },
        login: function () {
        /// <summary>
        /// Login facebook button clicked
        /// </summary>
        log("login facebook button clicked");
    
        if (window.FB) {
    
            //Windows phone does not enter this method, Android and Iphone do
            window.FB.login(function (response) {
    
                if (response.status) {
                    log('it means the user has allowed to communicate with facebook');
    
                    fbAccessToken = response.authResponse.accessToken;
                    window.FB.api('/me', function (response) {
                        //get information of the facebook user.
                        loginService.subscribeSocialUser(response.id, response.first_name, response.last_name, fbAccessToken, "", "FaceBook", fbSucces, fbFail);
    
                    });
                } else {
                    log('User cancelled login or did not fully authorize.');
    
                }
            },
            { scope: 'email'
            });
        }
    
    }
    };
    

    添加频道 URL 以解决任何跨浏览器问题。 它应该指向一个引用js的html文件,如下所示:

    <script src="//connect.facebook.net/en_US/all.js"></script>
    

    如果在初始化 Facebook.js 时遇到错误,您将无法成功登录。

    您可以同步或异步加载 java 脚本。

    (function(d, debug){
         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" + (debug ? "/debug" : "") + ".js";
         ref.parentNode.insertBefore(js, ref);
       }(document, /*debug*/ false));
    

    【讨论】:

    • 谢谢。我已经使用 FB 的 php 重定向选项实现了。
    猜你喜欢
    • 1970-01-01
    • 2011-06-09
    • 1970-01-01
    • 1970-01-01
    • 2018-03-15
    • 2015-03-03
    • 2011-08-21
    • 2020-09-01
    • 1970-01-01
    相关资源
    最近更新 更多