views:

93

answers:

1

Can the current Facebook Javascript SDK work with older Facebook API library?

Right now there is code to load the current Facebook Javascript SDK by:

window.fbAsyncInit = function() {
    FB.init({appId: '218565466928', status: true, cookie: true,
             xfbml: true});
};
// [...] initialize it

And there is code to use the old Facebook API by

init_fb_connect('Connect', 'XFBML', :js => :jquery, :app_settings=> '{ifUserNotConnected: fb_user_not_connected}' ) do

which is the Facebooker Rubygem. Can they work together somehow? If I have both, then the newly added "Like" button won't work. If I remove the older Facebooker code, then the "Login with Facebook" and "Share" button won't work. Any ideas?


Update: the older code do things like:

<a class="facebook-connect-link " href="#" 
  onclick="; FB.Connect.requireSession(fb_after_connect, null, true); return false;"
  rel="nofollow">Sign in with Facebook</a>  

and

<a href="#" onclick="FB.Connect.streamPublish('', {'name': 'Some product name' ...

and

  $('.login-button').each(function() {
    FB.XFBML.Host.addElement(new FB.XFBML.LoginButton(this));  
  })
+1  A: 

Converting javascript API is relatively easy. Not sure how much your server side will be affected though. Here is basic methods that you would probably need:

//check if user is logged in right now
FB.getLoginStatus(function(response) {
  if (response.session) {
    // logged in and connected user, someone you know
  } else {
    // no user session available, someone you dont know
  }
});

//callback fired when user logs out/logs in
FB.Event.subscribe('auth.sessionChange', function(response) {
  // do something with response.session
});

//to force login (on login btn click)
FB.login(function(response) {
  if (response.session) {
    // user successfully logged in
    fb_after_connect();
  } else {
    // user cancelled login
  }
});

//post to feed
FB.api('/me/feed', 'post', { body: "message" }, function(response) {
  if (!response || response.error) {
    alert('Error occured');
  } else {
    alert('Post ID: ' + response);
  }
});

If you don't want to convert to new API then you can embed like button as iframe. Sooner or later you would have to convert your project anyway so might as well do it now.

serg
I see. maybe part of the work will be to find all the old code and remove them as well... but i guess it will be either the initialization or the code doing the work, which will be converted to using the new SDK. thanks.
動靜能量