NetManiac

Witold Rugowski on web20 wave with Ruby on Rails

Interacting with Facebook without user

Posted on November 12, 2007 - Filed Under Facebook, howto, Ruby, RubyOnRails

As a developer of applications based on Facebook Platform I was asking myself how to make changes in user profile not only when user is interacting with application directly.

Users sessions are infinite

First Eureka was to understand, that with Facebook Platform web application, every user session is infinite (does not expire) as long as user has application added to it’s profile. With such session key, Your application can connect to Facebook API and send FBML to user profile. More, it don’t has to be the same user whom session key is used (but, of course, both of users have to have Your application added to theirs profile).

How to connect to API

When connecting from outside of web application, You need to setup session by itself. Of course it does not mean You need to write all code. Probably You need to connect to Your database anyway, so using script/runner is obvious. With runner You can write parts of Rails powered web application, and run it without HTTP request triggering events.

Using RFacebook is also obvious. Only one thing left, how to initialize fbsession? Assuming, that for each user You store in User model filed fbsession for user session key (Facebook session), You can do it with:

   fbsession = RFacebook::FacebookWebSession.new FACEBOOK["key"], FACEBOOK["secret"]
   fbsession.activate_with_previous_session User.find(:first, :conditions => "fbsession IS NOT NULL").fbsession

At this point fbsesison.is_valid? should be returning true, and You can make needed calls to Facebook API.

Popularity: 5% [?]

Hits for this post: 4367

Similar Posts

Comments

2 Responses to “Interacting with Facebook without user”

  1. inztinkt on June 5th, 2008 18:41

    You can also use as a template and run a cron to update the handle as often as u wish, on all profiles ;)

    see it in action in my Cyprus Evens Application at http://apps.facebook.com/onthisisland/

    Enjoy :)

  2. inztinkt on June 5th, 2008 18:45

    sorry i meant use

Leave a Reply