Facebook Connect With Rails

2009 September 14
by Hamed
Share

I just finished up with our Facebook Connect integration on Radio Javan’s site to allow users to to login to our site via their Facebook account. While I was lucky enough that there are some good Rails guides and API helpers, it was still an interesting experience. The FB APIs are pretty straightforward, but at the end of the day you are at the mercy of FB on whether or not anything actually works!

  • I started off with this great guide and example project. Like most Facebook/Rails integrations, this project makes use of the awesome Facebooker library — I say “awesome” because the author still keeps it updated.
  • Part of getting the integration working is that you have to send a “facebook.connect.registerUsers” command to register your existing users with FB. This API allows you to send accounts in batches of 1,000 — but it doesn’t work if you do it that high (you get HTTP errors and no-ops). In fact, I couldn’t even get it working in batches of 100, so I just ended up doing a call for each user (that would be almost 40,000+ calls for RJ).
  • One important thing to note is that FB never sends the account’s email address to you. So if you want to know a new user’s email address (which is a must for RJ), then you should just simply ask for it in a signup form after they authenticated your app thru FB.
  • A tricky problem is what to do if the user already has an account on your website with a DIFFERENT email address than their FB account. I’m still trying to figure this one out — I’ve seen other sites simply tell the users not to do this and use the same email, and I don’t think that’ll be a friendly behavior. Right now, I look to see if the user is already logged into RJ and determine it based on that.
  • Oh, this post would not be complete without a great Internet Explorer story. So if parts of your site runs on SSL, then you need to include the SSL versions of Facebook’s Javascript files (which in turn pulls in the SSL versions of images, css, etc that it needs). The reason for this is to avoid the classic “this page both contains secure and non-secure items” from IE. So what happens when you use the SSL resources from Facebook? A big, ugly, show-stopping Javascript error (and why does it have to be about Flash?). The reason I mentioned earlier you are the mercy of FB is because I think this used to work, and they updated their JS library recently as the bugs just started showing up for people the last few weeks. My answer for now: no SSL pages for in IE — IE users don’t really care about security, do they?

Anyways, now that my integration is complete, I’m looking forward in doing more things such as publishing to the news feed. And did anyone say Facebook Connect with iPhone?

One Response leave one →
  1. 2009 September 14

    Great post on the ins and outs of facebook connect integration with an existing webapp. While your post title is rails-specific, most of what you write about is actually applicable for any technology stack.

    For instance, when we were adding Facebook Connect to the Wildfire Platform (built on a JEE stack) we ran into all of these same issues – the registerUsers call being very flaky (we had to ratchet our batch sizes down to 250 and do it in the middle of the night), figuring out the existing account versus new account flow, and buggy facebook JS code.

    One thing we did end up doing that you don’t mention is giving the user a choice once they “connect” if their email does not match up immediately. You mention that you just tell users not to do this. Well, obviously this is not a great experience – so we send them to a screen that asks them – “Do you want to create a new account, or connect with your existing account?” This way, you force the user to decide and you don’t end up with duplicate accounts (and they don’t have to log in prior to facebook connecting).

    Maybe that’s something you could do on RJ?

    Cheers,
    -Zach

Leave a Reply

Note: You can use basic XHTML in your comments. Your email address will never be published.

Subscribe to this comment feed via RSS