无法使用 Koala 连接 Facebook(使用 Rails)获取 Oauth facebook cookie

发布于 2024-12-13 19:33:34 字数 1066 浏览 0 评论 0原文

我正在使用 Rails 3.0.9。 尝试通过 Facebook 登录我的 (localhost) 网站。

我在登录页面上的初始化参数:

FB.init({
      appId : '<%= FB_APP_ID %>',
      status : true,
      cookie : true,
      xfbml : true
});

登录按钮有效,我收到 Facebook 登录弹出窗口,并且可以成功登录 Facebook。 然后发生以下事件:

FB.Event.subscribe('auth.sessionChange', function(response) {
    if (response.session) {location.href= ...}

我被重定向到所需的位置。 但是 - 无法获取任何“fbs_”或“fbsr_”的 cookie,就像 Oauth 正在寻找的那样: get_user_info_from_cookie(cookies)

我的 cookies = {},那里什么也没有。 有几次,我记得我确实有一些 facebook cookie,我无法重建这种情况,但无论如何,它不包括“fbs_”cookie,只包括其他cookie。

另外,登录后,当我返回浏览器上的 Facebook 选项卡并刷新时,它确实会显示我的 Facebook 页面,但一秒钟后,它会显示一个弹出窗口,显示“您需要登录”。不过,在我的应用程序中,它仍然知道继续将我定向到所需的 href,就像用户登录时所需的那样。

我真的很想听听您是否有任何可以帮助我的信息...:-)

谢谢, 穆兹利。

  • 刚刚再次获得一些 Facebook cookie 的场景(仍然不是想要的名称)。获得以下名称:“datr”、“locale”、“locale”、“reg_fb_gate”、“lu”。 但即使是这些我也无法使用 Rails cookies 参数 - cookies["dart"] 返回 null。 cookies 参数仅显示 localhost 主机的 cookie(其中包含我登录时的数据(带有许可)- 站点的常规登录过程。

I'm using Rails 3.0.9.
Trying to login to my (localhost) site through Facebook.

My init params on the login page:

FB.init({
      appId : '<%= FB_APP_ID %>',
      status : true,
      cookie : true,
      xfbml : true
});

The login button works, I get the Facebook login popup and I can successfully log in to Facebook.
Then the following event is reached:

FB.Event.subscribe('auth.sessionChange', function(response) {
    if (response.session) {location.href= ...}

And I'm being redirected to the wanted location.
But - can't get any cookies of "fbs_" or "fbsr_" like the Oauth is looking for at: get_user_info_from_cookie(cookies)

My cookies = {}, nothing there.
In a few occasions, I recall I did have some facebook cookies there, I can't reconstruct such case, but anyway, it didn't include the "fbs_" ones, only others.

Also, after logging in, when I go back to Facebook tab on the browser and refresh, it does show me my Facebook page, but after a second, it shows a popup says "you need to log in". In my app though, it still knows to keep directing me to the wanted href, like needed when a user is logged in.

I would really love to hear if you have anything that can help me... :-)

Thanks,
Moozly.

  • Just got the scenario with some Facebook cookies again (still not by the wanted names). Got the following names: "datr", "locale", "locale", "reg_fb_gate", "lu".
    But even to these I can't get to with the Rails cookies param - cookies["dart"] returns null.
    cookies param only shows the cookies with the host of localhost (which contains data when I'm logging in (with Clearance) - the regular login procedure to site.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

花海 2024-12-20 19:33:35

只是想更新说我已经解决了我的问题:

  1. 我已在 init 中添加了参数:oauth : true:

    FB.init({
        appId : '<%= FB_APP_ID %>',
        状态:真实,
        饼干:真实,
        xfbml:正确,
        验证:正确
    });
    
  2. 显然,添加参数时存在错误
    js.src,所以我删除了它们(!),问题就解决了:

    <代码>(函数(d, s, id) {
        var js, fjs = d.getElementsByTagName(s)[0];
        if (d.getElementById(id)) {返回;}
        js = d.createElement(s); js.id = id;
        js.src = "//connect.facebook.net/en_US/all.js" //删除:#xfbml=1&appId=<%= FB_APP_ID %>";
        fjs.parentNode.insertBefore(js, fjs);
    }
    (文档,'脚本','facebook-jssdk')); 
    

这为我解决了cookie问题!

Just wanted to update to say that I had solved my problem:

  1. I had added to the init the param: oauth : true:

    FB.init({
        appId : '<%= FB_APP_ID %>',
        status : true,
        cookie : true,
        xfbml : true,
        oauth : true
    });
    
  2. Apparently, there is a bug with adding the parameters added in
    js.src, so I removed them(!) and problem was solved:

    (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_US/all.js" //removed: #xfbml=1&appId=<%= FB_APP_ID %>";
        fjs.parentNode.insertBefore(js, fjs);
    }
    (document, 'script', 'facebook-jssdk')); 
    

That solved the cookies problem for me!

ˇ宁静的妩媚 2024-12-20 19:33:35

如果您想使用 localhost 进行 facebook 开发,请将“127.0.0.1 localhost.local”记录添加到您的 /etc/hosts 文件中,更改 Developers.facebook.com 中应用程序设置中的域并将浏览器指向此 url - 它可以完美运行

if you want to use localhost for facebook development, add "127.0.0.1 localhost.local" record to your /etc/hosts file, change domain in application settings in developers.facebook.com and point browser to this url - it works flawlessly

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文