Facebook身份验证对话框(JS SDK)返回空白屏幕

时间:2011-11-12 08:17:22

标签: ruby-on-rails-3 facebook facebook-oauth facebook-javascript-sdk

我正在设置一个rails应用程序并试图通过Facebook JS SDK实现登录。已经错过了Omniauth ...... :(

无论如何,发生的事情是弹出对话框,用户提供登录信息,然后重定向到https://www.facebook.com/connect/window_comm.php?_id=some-string&_relation=opener&auth_token=some-big-string,一个空白屏幕。弹出窗口没有关闭。

如果我手动关闭它,然后刷新我的页面,我可以看到登录发生了。

奇怪的是,在第一次登录时,当要求权限时,一切都按预期工作,在授予或拒绝权限后弹出窗口关闭。

在Chrome,FF,Safari和Opera上测试过。一致的行为。

如果我在Chrome上调试空白重定向页面,则会出现两个错误:

1)Unsafe JavaScript attempt to access frame with URL http://something from frame with URL https://something. Domains, protocols and ports must match.(注意http x https ...)

2)window_comm.php:7Uncaught TypeError: Cannot call method '_recv' of undefined

以下是相关代码:

<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : 'my-app-id',
      status     : true,
      channelURL : 'http://localhost:3000/channel.html',
      cookie     : true,
      oauth      : true,
      xfbml      : true
    });

    FB.Event.subscribe('auth.login', function(response) {
      window.location.reload();
    });
  };
  (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/pt_BR/all.js"
    fjs.parentNode.insertBefore(js, fjs); 
    } 
    (document, 'script', 'facebook-jssdk'));
</script>
<div class="fb-login-button" data-show-faces="true" data-width="400" data-max-rows="1" perms="offline_access"></div>

非常感谢你对此的任何启示......让我疯了! =(

编辑:这可能是Facebook上的一个错误,因为它从http重定向到https?

1 个答案:

答案 0 :(得分:0)

这只回答Q.1)。 Facebook新要求: -

  • 切换到Oauth2.0以获取token_access
  • 使用SSL(即:https://)进行身份验证(因此跨域问题)

此外,我通常从下面的代码开始,以确定登录过程中可能的用户状态。这意味着在测试阶段点击任何内容和所有内容。

FB.Event.subscribe('auth.authResponseChange', function(response) {
    alert('The status of the session is: ' + response.status);
});
相关问题