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.
Leave a Reply