[Facebooker-talk] Session key invalid or no longer valid
Adeel Ahmad
adeel at proletariandesign.com
Sun Feb 1 16:26:24 EST 2009
Thanks, this looks like it should do well for now. However it's not catching
the exception... must be some other config I have wrong. Odd.
module Facebooker
module Rails
module Controller
include Facebooker::Rails::ProfilePublisherExtensions
def self.included(controller)
controller.extend(ClassMethods)
controller.before_filter :set_adapter
controller.before_filter :set_fbml_format
controller.helper_attr :facebook_session_parameters
controller.helper_method :request_comes_from_facebook?
controller.rescue_from Facebooker::Session::SessionExpired, :with =>
:facebook_session_expired
end
def facebook_session_expired
clear_fb_cookies!
clear_facebook_session_information
flash[:error] = "Your facebook session has expired."
redirect_to root_url
end
- Adeel
On Sun, Feb 1, 2009 at 11:09 AM, kevin lochner <klochner at gmail.com> wrote:
> I'm using a rescue. I tried advancing this discussion a couple weeks ago -
> the problem is that to really *know* that the session is valid, you have to
> try using it (i.e., hit the facebook rest server with a request). I think
> it's a waste toconstantly ping the facebook server just to make sure you
> don't get an invalid session error when you're not expecting it, especially
> given that this scenario will be low-frequency with respect to total
> requests.
>
> So here's what I did in facebooker/rails/controller.rb:
>
> module Facebooker
> module Rails
> module Controller
> def self.included(controller)
> controller.rescue_from Facebooker::Session::SessionExpired, :with
> => :facebook_session_expired
> end
>
> def facebook_session_expired
> clear_fb_cookies!
> clear_facebook_session_information
> flash[:error] = "Your facebook session has expired."
> redirect_to root_url
> end
>
> I'm hesitant to add this to facebooker because i'm not convinced everyone
> will want to do it this way, and
> it probably means adding another parameter like "expired_session_url" so
> that this exception handling
> works out of the box (since not everyone will redirect to root_url).
>
> - kevin
>
>
> On Feb 1, 2009, at 12:51 PM, Adeel Ahmad wrote:
>
> This may be related to Aaron's question on Jan. 30. However in my case I
> doing Facebook Connect using Facebooker for my site.
> Following the Facebook Connect tutorial it does create a session and show
> the user as logged in. For now I have the same 'fb' controller just to demo
> log in.
> However if the user logs out at facebook.com and then refreshes fb/index
> on my site, I get "Session key invalid or no longer valid" on the line that
> outputs @facebook_session.user.name. Just FYI if I output
> @facebook_session.user.to_s it does give me the uid.
> If you look at the stack trace below you'll notice that it passes through a
> number of actions that test for existence and validity of the session. It
> has a problem in the Error class of parser.rb. I would think it should catch
> the problem a lot earlier than in parser.rb.
> Any thoughts on how to troubleshoot and/or workaround this? I'm on Rails
> 2.1.1.
>
> ========================================
> Facebooker::Session::SessionExpired in Fb#index
>
> Showing fb/index.html.erb where line #10 raised:
>
> Session key invalid or no longer valid
>
> Extracted source (around line #10):
>
> 7: <%= fb_login_button%>
> 8:
> 9: <% if facebook_session %>
> 10: <h2>You are logged in as <%= facebook_session.user.name %></h2>
> 11: <% else %>
> 12: <h2>You are not logged in!</h2>
> 13: <% end %>
>
> vendor/plugins/facebooker/lib/facebooker/parser.rb:487:in `process'
> vendor/plugins/facebooker/lib/facebooker/parser.rb:15:in `parse'
> vendor/plugins/facebooker/lib/facebooker/service.rb:20:in `post'
> vendor/plugins/facebooker/lib/facebooker/session.rb:473:in
> `post_without_logging'
> vendor/plugins/facebooker/lib/facebooker/session.rb:484:in `post'
> vendor/plugins/facebooker/lib/facebooker/logging.rb:27:in `log_fb_api'
> vendor/rails/activesupport/lib/active_support/core_ext/benchmark.rb:8:in
> `realtime'
> vendor/plugins/facebooker/lib/facebooker/logging.rb:27:in `log_fb_api'
> vendor/plugins/facebooker/lib/facebooker/session.rb:483:in `post'
> vendor/plugins/facebooker/lib/facebooker/models/user.rb:120:in `populate'
> vendor/plugins/facebooker/lib/facebooker/model.rb:35:in `name'
> app/views/fb/index.html.erb:10:in
> `_run_erb_47app47views47fb47index46html46erb'
>
>
> --
> - Adeel
>
>
>
> _______________________________________________
> Facebooker-talk mailing list
> Facebooker-talk at rubyforge.org
> http://rubyforge.org/mailman/listinfo/facebooker-talk
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/facebooker-talk/attachments/20090201/7b1c2904/attachment-0001.html>
More information about the Facebooker-talk
mailing list