www.flickr.com
Michael Kovacs' photos More of Michael Kovacs' photos
Recommend Me Cable Car Software logo

Thursday, January 31, 2008

Rails realities part 27 (Facebook and Bebo sittin in an app)

Long time no post. Way too long. I'm not a big fan of too much noise so I try to post when I have something that I think is important to share.

Anyway, today I've got something to share that all you web2.0-facebook-bebo-social-networking-rails-app-building monkeys have been clamoring for but so far have only had a half baked solution to.... Running your Facebook apps on Bebo using RFacebook.

"Wait a minute, you CAN do that right now dude, catch up!" Ahh yes my little ruby fanboy there IS a solution out there right now, the RFacebook on Bebo plugin, BUT that only allows you to run the same app on EITHER Facebook or Bebo. That means you need to setup another VHost and another cluster of mongrels which you may not want to do (I don't).

"Dude, you're still behind man, that wizard Chad Fowler done started his own Facebook integration project called Facebooker." Yeah I know about that thing too and while it is said RFacebook is not long for this world, right now I've got a "legacy" (hehe) rails facebook app and at the moment upgrading to Facebooker isn't as attractive of an option for a live app vs. modifying the existing plugin/gem that's being used.

I've done the dirty work of hacking through RFacebook 0.9.8 and performing the necessary surgery to make RFacebook work on any network that's compatible with the Facebook API. In my case I've added support for Bebo. (The only other "facebook compatible" network I know of)

How about some code?
In the RFacebook GEM in facebook_session.rb...
module RFacebook
# TODO: better handling of session expiration
# TODO: support Bebo's API
HOST_CONSTANTS = { 'facebook' => { :api_version => "1.0",
:api_host => "api.facebook.com",
:api_path_rest => "/restserver.php",
:www_host => "www.facebook.com",
:www_path_login => "/login.php",
:www_path_add => "/add.php",
:www_path_install => "/install.php"},
'bebo' => { :api_version => "1.0",
:api_host => "apps.bebo.com",
:api_path_rest => "/restserver.php",
:www_host => "bebo.com",
:www_path_login => "/SignIn.jsp",
:www_path_add => "/add.php",
:www_path_install => "/c/apps/add"}}

If there were another network to come along all you'd need to do is add a couple of constants in the RFacebook GEM for a new network and modify the config file for your new network. Now I don't know of any other "Facebook compatible" social networks out there besides Bebo at the moment but here's where you'd add their information if there were.

Now there are two burdens on you the user:

  1. The plugin determines what network requests are coming from by checking for a subdomain (i.e. http://bebo.mkovacs.com, http://facebook.mkovacs.com). Therefore you have to tell Facebook and Bebo your callback address is one that begins with the subdomain you're on.
  2. There is a slight change in the facebook.yml config file. Example:

development:
facebook:
key: (key)
secret: (secret)
canvas_path: /pitchwire/
callback_path: /facebook/
tunnel:
username: user
host: pitchwire.com
port: 1099
local_port: 3000
bebo:
key: (key)
secret: (secret)
canvas_path: /pitchwire/
callback_path: /facebook/
test:
facebook:
key: (key)
secret: (secret)
canvas_path: /pitchwire/
callback_path: /facebook/
bebo:
key: (key)
secret: (secret)
canvas_path: /pitchwire/
callback_path: /facebook/
production:
facebook:
key: (key)
secret: (secret)
canvas_path: /pitchwire/
callback_path: /facebook/
bebo:
key: (key)
secret: (secret)
canvas_path: /pitchwire/
callback_path: /facebook/

So as you can see it's pretty much the same except that for each environment there's a facebook: and a bebo: setting.

"OK great, gimme, gimme, gimme!!" Hmmm... well I've contacted the RFacebook project owner to provide him with the changes so he can integrate them and probably do a point release, but in this instant-gratification-web2.0-gotta-have-it-now-gimme-so-I-can-get-dugg world I'll put the files up on my rinky dink shared hosting site until there's an update to the codebase and a release.

Now for the disclaimer. This comes with the 'WTFPL' license and DIY support :-)

Update: I've checked the modified rfacebook code into the rfacebook project in a branch. For more information and to pickup the code go here: http://rfacebook.rubyforge.org/svn/branches/rfacebo/

Simply:

  1. Replace your installed RFacebook-0.9.8 GEM (or 0.9.7) with the contents of the GEM zip.
  2. Replace your installed rfacebook plugin (If you have 0.9.7 you can delete rfacebook_on_rails in your plugin directory) in your app with the zipped up plugin.
  3. Modify your facebook.yml file to match the format above and include your settings for Facebook and Bebo in whatever environment you choose.

(For you folks using the RFacebook on Bebo plugin you can go ahead and remove that)

After that you should be able to hit your application from either Bebo or Facebook without having to setup different mongrel instances. Let me know if I've missed something and I'll update this post or the zips. Or join the discussions on the google group. (I'd say to use the groups on the RFacebook site but the app is currently broken).

Enjoy!

This page is powered by Blogger. Isn't yours?