1

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.
4

2 に答える 2

1

問題を解決したと言って更新したかっただけです:

  1. init に param: を追加しましたoauth : true

    FB.init({
        appId : '<%= FB_APP_ID %>',
        status : true,
        cookie : true,
        xfbml : true,
        oauth : true
    });
    
  2. どうやら、js.src に追加されたパラメーターの追加にバグがあるようです。そのため、それらを削除して (!)、問題は解決しました。

    (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')); 
    

これで Cookie の問題は解決しました。

于 2011-11-06T22:07:49.403 に答える
0

Facebook の開発に localhost を使用する場合は、「127.0.0.1 localhost.local」レコードを /etc/hosts ファイルに追加し、developers.facebook.com のアプリケーション設定でドメインを変更し、ブラウザーをこの URL に向けます。問題なく動作します。

于 2013-12-04T22:58:39.340 に答える