3

我正在设置一个 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 吗?

4

1 回答 1

0

这仅回答 Q.1)。脸书新要求:-

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

另外,我通常会从下面的代码开始,以找出登录过程中可能的用户状态。这意味着在测试阶段点击任何东西。

FB.Event.subscribe('auth.authResponseChange', function(response) {
    alert('The status of the session is: ' + response.status);
});
于 2011-11-12T18:16:42.170 回答