Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript FB.getLoginStatus不';不能在Chrome甚至沙盒中工作禁用_Javascript_Ruby On Rails_Omniauth - Fatal编程技术网

Javascript FB.getLoginStatus不';不能在Chrome甚至沙盒中工作禁用

Javascript FB.getLoginStatus不';不能在Chrome甚至沙盒中工作禁用,javascript,ruby-on-rails,omniauth,Javascript,Ruby On Rails,Omniauth,我按照railscast在我的网站上添加了“使用Facebook登录”功能,登录没有问题。但当尝试注销时,即使我在facebook开发者应用程序设置中禁用了沙盒模式,FB.getLoginStatus似乎也从未被激活(如其他一些讨论中所建议的): 单击“注销”时,我无法看到我的警报 我运行的Chrome和Firefox具有相同的行为。谁能帮我找出我遗漏了什么?非常感谢 让我更具体地描述一下我遇到的“行为”: 第一次从mysite.com登录Facebook时,Facebook登录窗口将弹出并询问

我按照railscast在我的网站上添加了“使用Facebook登录”功能,登录没有问题。但当尝试注销时,即使我在facebook开发者应用程序设置中禁用了沙盒模式,FB.getLoginStatus似乎也从未被激活(如其他一些讨论中所建议的):

单击“注销”时,我无法看到我的警报

我运行的Chrome和Firefox具有相同的行为。谁能帮我找出我遗漏了什么?非常感谢

让我更具体地描述一下我遇到的“行为”:

  • 第一次从mysite.com登录Facebook时,Facebook登录窗口将弹出并询问电子邮件和密码,我可以完全正常登录到我的网站并按预期工作
  • 然后我点击mysite.com/users/1上的sign_out按钮,看起来好像是注销ok
  • 然后再次从mysite.com登录Facebook,现在它将不再弹出Facebook登录窗口,直接登录mysite.com/users/1而不询问电子邮件和密码
  • 如果我打开另一个浏览器窗口,进入facebook.com并从那里注销,那么当我从mysite.com登录facebook时,它现在会弹出一个facebook登录窗口,询问我的电子邮件和密码
  • 我希望我的网站能够正常运行:“当从mysite.com/users/n注销并从mysite.com再次登录Facebook时,Facebook登录窗口将弹出”

    有人能帮忙吗?非常感谢

    编辑:

    进一步调查发现,“根本”原因可能仍然是:注销位于登录路径的不同路径(或页面)下,FB.getLoginStatus无法在mysite.com/signout下启动。firebug的错误消息表示“应用程序配置不允许给定URL。应用程序的设置不允许一个或多个给定URL。它必须与网站URL或画布URL匹配,或者域必须是应用程序域之一的子域。”

    为了证明这是路由问题,我在与登录路由相同的路由(页面)中放置了一个注销链接,这是“使用Facebook登录的网站”中指定的根路由mysite.com,一切正常,可以按预期注销:

    <%= link_to "sign out facebook", "#" , id: "sign_out" %>
    
    因此,底线是:FB.getLoginStatus可能仍然有一个bug,它无法处理来自不同于登录路由的呼叫。(我用Chrome、Firefox和Safari进行了测试,它们的表现都是一样的,但对IE10来说却不一样。不知何故,IE10甚至可以在不同的路径上注销。)


    有类似问题的人有何评论?请告知。非常感谢。请尝试将true作为第二个参数添加到getLoginStatus,如FB dev doc中所述:

    FB.getLoginStatus(function(response) {
      // this will be called when the roundtrip to Facebook has completed
    }, true);
    
    这应该避免缓存。 另一个选项是订阅事件:

    FB.Event.subscribe('auth.login', function(response) {
      // do something with response
    });
    
    全部来自

    如果您有问题,请发表评论

    编辑:

    我稍微修改了你的脚本,删除了不需要的代码部分。你有太多不需要的回报。我尝试在这个修改过的脚本中注销,它可以根据您的需要工作。 事件订阅用于检查目的

    <head>
        <title>Exam entry</title>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
    </head>
    <body>
        <div id="fb-root"></div>
    
        <input type="button" value="Sign in" id="sign_in" />
        <input type="button" value="Sign out" id="sign_out" />
    
        <script type="text/javascript">
            window.fbAsyncInit = function () {
                FB.init({
                    appId: '586844044669652',
                    cookie: true,
                    status: true,
                    xfbml: true
                });
    
    
                // Here we subscribe to the auth.authResponseChange JavaScript event. This event is fired
                // for any authentication related change, such as login, logout or session refresh. This means that
                // whenever someone who was previously logged out tries to log in again, the correct case below 
                // will be handled. 
                FB.Event.subscribe('auth.authResponseChange', function (response) {
                    // Here we specify what we do with the response anytime this event occurs. 
                    if (response.status === 'connected') {
                        // The response object is returned with a status field that lets the app know the current
                        // login status of the person. In this case, we're handling the situation where they 
                        // have logged in to the app.
                        testAPI();
                    } /*else if (response.status === 'not_authorized') {
                        // In this case, the person is logged into Facebook, but not into the app, so we call
                        // FB.login() to prompt them to do so. 
                        // In real-life usage, you wouldn't want to immediately prompt someone to login 
                        // like this, for two reasons:
                        // (1) JavaScript created popup windows are blocked by most browsers unless they 
                        // result from direct interaction from people using the app (such as a mouse click)
                        // (2) it is a bad experience to be continually prompted to login upon page load.
                        FB.login();
                    } else {
                        // In this case, the person is not logged into Facebook, so we call the login() 
                        // function to prompt them to do so. Note that at this stage there is no indication
                        // of whether they are logged into the app. If they aren't then they'll see the Login
                        // dialog right after they log in to Facebook. 
                        // The same caveats as above apply to the FB.login() call here.
                        FB.login();
                    }*/
                });
    
    
                $('#sign_in').click(function (e) {
                    e.preventDefault();
                    FB.login(function (response) {
                        if (response.authResponse) {
                            //return window.location = '/auth/facebook/callback';
                        }
                    });
                });
                $('#sign_out').click(function (e) {
                    FB.logout(function (response) {
                        console.log("Here logout response", response);
                    });
                });
    
            };
    
            // Here we run a very simple test of the Graph API after login is successful. 
            // This testAPI() function is only called in those cases. 
            function testAPI() {
                console.log('Welcome!  Fetching your information.... ');
                FB.api('/me', function (response) {
                    console.log('Good to see you, ' + response.name + '.');
                });
            }
    
            // Load the SDK asynchronously
            (function (d) {
                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.js";
                ref.parentNode.insertBefore(js, ref);
            }(document));
        </script>
    </body>
    
    
    报考
    window.fbAsyninit=函数(){
    FB.init({
    appId:'586844044669652',
    曲奇:是的,
    状态:正确,
    xfbml:对
    });
    //这里我们订阅auth.authResponseChangeJavaScript事件
    //用于任何与身份验证相关的更改,例如登录、注销或会话刷新
    //每当以前注销的用户尝试再次登录时,下面的正确案例
    //我们会处理的。
    FB.Event.subscribe('auth.authResponseChange',函数(响应){
    //在这里,我们指定在发生此事件时如何处理响应。
    如果(response.status===“已连接”){
    //响应对象返回一个状态字段,让应用程序知道当前状态
    //此人的登录状态。在本例中,我们正在处理他们
    //已登录到应用程序。
    testAPI();
    }/*否则如果(response.status==“未授权”){
    //在这种情况下,此人登录了Facebook,但没有登录到应用程序,因此我们呼叫
    //FB.login()来提示他们这样做。
    //在现实生活中,您不会希望立即提示某人登录
    //像这样,有两个原因:
    //(1)大多数浏览器都会阻止JavaScript创建的弹出窗口,除非
    //使用该应用程序的用户直接交互的结果(如鼠标单击)
    //(2)页面加载时不断提示登录是一种不好的体验。
    FB.login();
    }否则{
    //在本例中,此人未登录Facebook,因此我们称其为login()
    //函数提示他们这样做。请注意,在此阶段没有任何指示
    //他们是否登录到应用程序。如果他们没有,他们将看到登录
    //在他们登录Facebook后立即进行对话。
    //上面的警告同样适用于这里的FB.login()调用。
    FB.login();
    }*/
    });
    $(“#登录”)。单击(函数(e){
    e、 预防默认值();
    FB.登录(功能(响应){
    if(response.authResponse){
    //return window.location='/auth/facebook/callback';
    }
    });
    });
    $(“#注销”)。单击(函数(e){
    FB.注销(功能(响应){
    
    FB.getLoginStatus(function(response) {
      // this will be called when the roundtrip to Facebook has completed
    }, true);
    
    FB.Event.subscribe('auth.login', function(response) {
      // do something with response
    });
    
    <head>
        <title>Exam entry</title>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
    </head>
    <body>
        <div id="fb-root"></div>
    
        <input type="button" value="Sign in" id="sign_in" />
        <input type="button" value="Sign out" id="sign_out" />
    
        <script type="text/javascript">
            window.fbAsyncInit = function () {
                FB.init({
                    appId: '586844044669652',
                    cookie: true,
                    status: true,
                    xfbml: true
                });
    
    
                // Here we subscribe to the auth.authResponseChange JavaScript event. This event is fired
                // for any authentication related change, such as login, logout or session refresh. This means that
                // whenever someone who was previously logged out tries to log in again, the correct case below 
                // will be handled. 
                FB.Event.subscribe('auth.authResponseChange', function (response) {
                    // Here we specify what we do with the response anytime this event occurs. 
                    if (response.status === 'connected') {
                        // The response object is returned with a status field that lets the app know the current
                        // login status of the person. In this case, we're handling the situation where they 
                        // have logged in to the app.
                        testAPI();
                    } /*else if (response.status === 'not_authorized') {
                        // In this case, the person is logged into Facebook, but not into the app, so we call
                        // FB.login() to prompt them to do so. 
                        // In real-life usage, you wouldn't want to immediately prompt someone to login 
                        // like this, for two reasons:
                        // (1) JavaScript created popup windows are blocked by most browsers unless they 
                        // result from direct interaction from people using the app (such as a mouse click)
                        // (2) it is a bad experience to be continually prompted to login upon page load.
                        FB.login();
                    } else {
                        // In this case, the person is not logged into Facebook, so we call the login() 
                        // function to prompt them to do so. Note that at this stage there is no indication
                        // of whether they are logged into the app. If they aren't then they'll see the Login
                        // dialog right after they log in to Facebook. 
                        // The same caveats as above apply to the FB.login() call here.
                        FB.login();
                    }*/
                });
    
    
                $('#sign_in').click(function (e) {
                    e.preventDefault();
                    FB.login(function (response) {
                        if (response.authResponse) {
                            //return window.location = '/auth/facebook/callback';
                        }
                    });
                });
                $('#sign_out').click(function (e) {
                    FB.logout(function (response) {
                        console.log("Here logout response", response);
                    });
                });
    
            };
    
            // Here we run a very simple test of the Graph API after login is successful. 
            // This testAPI() function is only called in those cases. 
            function testAPI() {
                console.log('Welcome!  Fetching your information.... ');
                FB.api('/me', function (response) {
                    console.log('Good to see you, ' + response.name + '.');
                });
            }
    
            // Load the SDK asynchronously
            (function (d) {
                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.js";
                ref.parentNode.insertBefore(js, ref);
            }(document));
        </script>
    </body>