integriting facebook login button with Facebooker (rails plugin)

Posted by dexterdeng on Stack Overflow See other posts from Stack Overflow or by dexterdeng
Published on 2011-01-08T13:41:08Z Indexed on 2011/01/09 3:54 UTC
Read the original article Hit count: 410

Filed under:
|

I was integriting login-button with Facebooker, as I wanted to use facepile and customise the facebook login button, so I have to use facebook js sdk.

I used the facebooker to connect facebook. now I found a issue.

window.fbAsyncInit = function() {
        FB.init({
                appId: '<%=Facebooker.api_key%>',
                status: true,
                cookie: true,
                xfbml: true
        });
};
(function() {
        var e = document.createElement('script');
        e.type = 'text/javascript';
        e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
        e.async = true;
        document.getElementById('fb-root').appendChild(e);
}());

 function fblogin(){
var pearms = "email,user_birthday,friends_location,offline_access,publish_stream,read_friendlists,user_birthday,user_location";

    FB.getLoginStatus(function(response) {
       if (response.session) {
          // logged in and connected user, someone you know
          window.location = "http://domain/account/link_user_accounts";
          return true;
       } else {
          // no user session available, someone you dont know
          FB.login(function(response) {
            if (response.session) {
              if (response.perms) {
                 // after logged in the facebook account. 
                 $.inspect(response.perms);//return all these  perms I expected.  it should be fine there. 
                 window.location = "http://domain/account/link_user_accounts";
               }
              return true;
            } else {                 
              return false;
            }
         },"email,user_birthday,friends_location,offline_access,publish_stream,read_friendlists");
     }    
  })
};

Let's say if the api_key is "1111111111". take a look at this line: "

 `   if (response.session) {
        if (response.perms) {
           $.inspect(response.perms); "

now I was trying to login , call fblogin() , I'm sure that the response.perms equal to the perms I expected. (btw, at that time, I have a facebook plugin named facepile works too, it showed my friends after I called fblogin() and connected to facebook by typing my email and password ).

so now it should run

 window.location = "http://domain/account/link_user_accounts";

yes, this line run. but the facebook_session can't build successfully. after digging the facebooker's code, I found this from the rails plugin facebooker:

  def create_facebook_session
    secure_with_facebook_params! || secure_with_cookies! || secure_with_token!
  end

mostly, it would run secure_with_cookies! , and if the cookies with keys as "fbs_#{Facebooker.api_key}","#{Facebooker.api_key}_ss", "#{Facebooker.api_key}_session_key",.. created, then the facebook_session can be created. but these cookies can't be created after I logged in facebook until I refresh the current page by hand . I noticed if I refresh the page, the cookies with these keys added to the browser.

but why they can't be added after I logged in facebook at once? I need these keys to create facebook_session. did I forgot something excepted these code I pasted?

anybody help?  thank you very much!

© Stack Overflow or respective owner

Related posts about login

Related posts about facebooker