Michael Tedesco
2008-Feb-29 16:58 UTC
[Facebooker-talk] Does anyone have an example of using facebooker with Infinite Sessions
Hi I am trying to set-up My facebook app to use infininite sessions. I saw the following link that used the old RFacebook libraries http://www.atnan.com/2007/6/18/updating-facebook-profiles-and-feeds-with-rfacebook Does anyone know of a sample app or example that does the same thing using facebooker and can provide Part of the controller code to do something like it. n Thanks, Mike -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/facebooker-talk/attachments/20080229/5c6a1a90/attachment.html
Christopher Bailey
2008-Feb-29 17:28 UTC
[Facebooker-talk] Does anyone have an example of using facebooker with Infinite Sessions
I haven''t looked at the app you mention, but the approach I take is just to store the session key, if it''s infinite, with the user''s DB record. That way, at any time, whether they''re in Facebook or not, I can update their profile FBML or send messages to the mini-feed etc. Basically, I just set up a before_filter on my Facebook controller, and in that it does a few specific things for our own app, but then calls the following which stores the key: def handle_infinite_session if facebook_session.infinite? if logged_in_user.facebook_session_key != facebook_session.session_key logged_in_user.update_attribute(:facebook_session_key, facebook_session.session_key) end else logger.warn "Non-infinite session key for Facebook session:\n" + " Facebook user ID: #{facebook_user.id}\n" + " Our user ID: #{logged_in_user.id}" end end On 2/29/08, Michael Tedesco <michael.tedesco at peermeta.com> wrote:> > Hi I am trying to set-up > > My facebook app to use infininite sessions. > > > > I saw the following link that used the old RFacebook libraries > > > http://www.atnan.com/2007/6/18/updating-facebook-profiles-and-feeds-with-rfacebook > > > > Does anyone know of a sample app or example that does the same thing > using facebooker and can provide > > Part of the controller code to do something like it. > > > > n Thanks, Mike > > _______________________________________________ > Facebooker-talk mailing list > Facebooker-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/facebooker-talk > >-- Christopher Bailey Cobalt Edge LLC http://cobaltedge.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/facebooker-talk/attachments/20080229/9bafb0fa/attachment.html
Christopher Bailey
2008-Feb-29 19:41 UTC
[Facebooker-talk] Does anyone have an example of using facebooker with Infinite Sessions
The Facebooker callback (ensure_...) will depend on what you need to do. I think in your case, you may need to do the installed one so that you are ok with getting their session key and storing it. But, honestly, I don''t know - you need to check the terms of use as to whether you are allowed to do things with a user session if they don''t have your app installed. But, the infinite session key, I believe, is independent of your app install (someone else can likely comment better on that, as I''m still somewhat new to Facebook and Facebooker and all these issues). For your second question, that looks about right. What I have found in my testing so far, is that I am always getting an infinite session key, and not even just when the user first installs the app, it seems to always be an infinite session. I don''t know if this is because I''m interacting via my Facebook app, or what (the Facebook documentation doesn''t imply that it''s always infinite, and further implies, at least to me, that it is not infinite beyond the workflow of adding your app, that''s why I have some of the logic I have to only update the key if it''s infinite and if it''s changed, etc.). In the end, what you have is good - whereby if you don''t have an infinite, you can use that magic URL they supply to ask the user to grant one to your app. This is a bit messy user interface/experience wise, but it may be what you have to do if you don''t have an infinite session key for whatever reason. On 2/29/08, Michael Tedesco <michael.tedesco at peermeta.com> wrote:> > My fault Chris, the below answers some of my questions thanks, but maybe > I can elaborate further. > > Here''s my thoughts > > > > 2 Basic questions > > 1) Does "ensure_authenticated_to_facebook " return a > permanent session key as well.? > > Is the advantage like you said below using below using the other > ensure_ method you gave means it only has to happen once? Right > > > > ensure_application_is_installed_by_facebook_user # this also ensures > they''re logged in to FB > > vs > > ensure_authenticated_to_facebook > > > > before_filter :sync_facebook_and_our_users > > > > 2) When I create the before_filter as you say > > > > Is this the order of my action going to be something like the following > below, because based on the doc if I have users that have expiring sessions > and I want to create a non expiring one, > > I need to forward to > > http://www.facebook.com/code_gen.php?v=1.0&api_key=YOUR_API_KEY > > > > *pardon for the psudo code* > > > > *sync_facebook_and_our_users* > > a) obtain fb user from facebook_session i.e at user > facebook_session.user > > b) Check if the user has a > > perm session entry in the DB > > If so, use it and continue? > > Otherwise, > > If not stored send user to the following to generate a non expiring > key? as directed in Doc > http://www.facebook.com/code_gen.php?v=1.0&api_key=YOUR_API_KEY > > Make a call to facebook.auth.getSession (store this new session in DB > for user) > > Continue? > > > > > > end > > > > What do you think Christopher, am I on the right track? > > > > > > *From:* Christopher Bailey [mailto:chris at cobaltedge.com] > *Sent:* Friday, February 29, 2008 1:13 PM > *To:* Michael Tedesco > *Subject:* Re: [Facebooker-talk] Does anyone have an example of using > facebooker with Infinite Sessions > > > > I might not be understanding what you''re after. In my controller, I do: > > > > class FacebookController < ApplicationController > ensure_application_is_installed_by_facebook_user # this also ensures > they''re logged in to FB > > before_filter :sync_facebook_and_our_users > ... > > > > Generally what''s happening here, is when the user first adds your app on > Facebook, you will see this infinite session key, store it along with their > user record in your own DB, and then never have to worry about it again. > Then, your application, can update the user''s profile or whatever, at any > time - regardless of whether the user is logged in, or even if that user is > using your application (whether inside Facebook or outside facebook). > > > > For example, we have user''s who belong to groups, in our own web app. If > a project within that group completes, say by user A''s actions, well, we can > still update the FB profile of all user''s of that group to indicate the > project is done, because we have their infinite session keys. So, at some > random point in your application, you can do something like: > > > > fb_session = Facebooker::Session.create > > fb_session.secure_with!(self.facebook_session_key, self.facebook_user_id, > 0) > > fb_session.user.profile_fbml = <insert your FBML here> > > > > My apologies if I''m not understand what you''re after or need. > > > > > > On 2/29/08, *Michael Tedesco* <michael.tedesco at peermeta.com> wrote: > > Hi Chris thanks, > > But any insight based on the auth document below, to work with the > call suggested in option 2 and to work with a before_filter using the > ensure_authenticated_to_facebook method. > > I''d like to store an infinite session regardless. > > http://developers.facebook.com/documentation.php?v=1.0&doc=auth > > > > > > *From:* Christopher Bailey [mailto:chris at cobaltedge.com] > *Sent:* Friday, February 29, 2008 12:28 PM > *To:* Michael Tedesco > *Cc:* facebooker-talk at rubyforge.org > *Subject:* Re: [Facebooker-talk] Does anyone have an example of using > facebooker with Infinite Sessions > > > > I haven''t looked at the app you mention, but the approach I take is just > to store the session key, if it''s infinite, with the user''s DB record. That > way, at any time, whether they''re in Facebook or not, I can update their > profile FBML or send messages to the mini-feed etc. Basically, I just set > up a before_filter on my Facebook controller, and in that it does a few > specific things for our own app, but then calls the following which stores > the key: > > > > def handle_infinite_session > > if facebook_session.infinite? > > if logged_in_user.facebook_session_key !> facebook_session.session_key > > logged_in_user.update_attribute(:facebook_session_key, > facebook_session.session_key) > > end > > else > > logger.warn "Non-infinite session key for Facebook session:\n" + > > " Facebook user ID: #{facebook_user.id}\n" + > > " Our user ID: #{logged_in_user.id}" > > end > > end > > > > > > On 2/29/08, *Michael Tedesco* <michael.tedesco at peermeta.com> wrote: > > Hi I am trying to set-up > > My facebook app to use infininite sessions. > > > > I saw the following link that used the old RFacebook libraries > > > http://www.atnan.com/2007/6/18/updating-facebook-profiles-and-feeds-with-rfacebook > > > > Does anyone know of a sample app or example that does the same thing > using facebooker and can provide > > Part of the controller code to do something like it. > > > > n Thanks, Mike > > > _______________________________________________ > Facebooker-talk mailing list > Facebooker-talk at rubyforge.org > http://rubyforge.org/mailman/listinfo/facebooker-talk > > > > > -- > Christopher Bailey > Cobalt Edge LLC > http://cobaltedge.com > > > > > -- > Christopher Bailey > Cobalt Edge LLC > http://cobaltedge.com >-- Christopher Bailey Cobalt Edge LLC http://cobaltedge.com -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/facebooker-talk/attachments/20080229/5cea16f4/attachment-0001.html
Joel Watson
2008-Feb-29 21:37 UTC
[Facebooker-talk] Does anyone have an example of using facebooker with Infinite Sessions
I do something similar in my app. To reinstantiate the session, I created a user method as follows: def restore_facebook_session return @facebook_session unless @facebook_session.nil? @facebook_session = Facebooker::Session.create(Facebooker::Session.api_key, Facebooker::Session.secret_key) @facebook_session.secure_with!(facebook_session_key, facebook_uid, 0) @facebook_session end I then use it as follows in the observer I have set up to update the user''s profile: def update_profile_fbml(membership) user = membership.user facebook_session = user.restore_facebook_session FacebookPublisher.deliver_profile_update(facebook_session.user, user) end Which is called like so: def after_create(membership) update_profile_fbml(membership) end def after_destroy(membership) update_profile_fbml(membership) end Some background. The app has users that can join groups (which are associated through memberships). These group memberships are then displayed in the user''s Facebook profile. So, whenever a membership is created or destroyed, their Facebook profile is updated accordingly. I wasn''t sure if there was a standard way of reinstantiating the session, so I tinkered around until I got the method shown above. If there''s a better way to do it, please speak up. :-) -Joel On Feb 29, 2008, at 9:28 AM, Christopher Bailey wrote:> I haven''t looked at the app you mention, but the approach I take is > just to store the session key, if it''s infinite, with the user''s DB > record. That way, at any time, whether they''re in Facebook or not, > I can update their profile FBML or send messages to the mini-feed > etc. Basically, I just set up a before_filter on my Facebook > controller, and in that it does a few specific things for our own > app, but then calls the following which stores the key: > > def handle_infinite_session > if facebook_session.infinite? > if logged_in_user.facebook_session_key != > facebook_session.session_key > logged_in_user.update_attribute(:facebook_session_key, > facebook_session.session_key) > end > else > logger.warn "Non-infinite session key for Facebook session:\n" + > " Facebook user ID: #{facebook_user.id}\n" + > " Our user ID: #{logged_in_user.id}" > end > end-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/facebooker-talk/attachments/20080229/76dc82dd/attachment.html