![]() | 'Session key invalid or no longer valid' notification issues |
|
25 Nov 2008, 08:03
Paul Fioravanti (13 posts) |
Hi there, I’m currently having fun working my way through the text but have hit a wall on page 93, Sending Notifications.
How do I generate new session keys for my test Facebook users? |
|
26 Nov 2008, 02:53
Paul Fioravanti (13 posts) |
Now I’m getting the following error:
I’ve tried looking back over what I’ve done so far, but I guess I’m finding the |
|
26 Nov 2008, 13:28
Mike Mangino (543 posts) |
Have you used the application recently as the user who you are sending the notification from? By default, Facebook sessions are only valid for about an hour from the time the user last uses your application. If you’re sending notifications via the web, this won’t be a big deal because each request renews the session. If you’re using script/console, you’ll need to make sure you visit your application in a browser once an hour or so. Mike |
|
27 Nov 2008, 00:43
Paul Fioravanti (13 posts) |
Thanks very much for the reply, Mike. I’m testing out all of my actions via the web (2 Facebook users running on web browsers on seperate machines), I tried de-authorizing the application on both users and then re-authorizing it, and reloading the fixtures into the After a bit of reading ahead, it seems that the issue was in the
def set_current_user
self.current_user = User.for(facebook_session.user.to_i)
end
The above Anyway, when I changed the code to how it is on page 125 below, the notifications got sent and I was able to view them as expected:
def set_current_user
set_facebook_session
# if the session isn't secured, we don't have a good user id
if facebook_session and
facebook_session.secured? and
!request_is_facebook_tab?
self.current_user = User.for(facebook_session.user.to_i,facebook_session)
end
end
|
|
27 Nov 2008, 00:59
Mike Mangino (543 posts) |
Good find! As much as I’d like to claim it as a printing error, it’s more likely an author error. Can you add this as an errata at http://www.pragprog.com/titles/mmfacer/errata ? That will remind me to fix it if we do another release of the PDF. Thanks and good luck with your application! Mike |
|
27 Nov 2008, 01:21
Paul Fioravanti (13 posts) |
Thanks Mike! Errata has been submitted. |
|
06 Mar 2009, 18:55
Nick Hoffman (10 posts) |
Hi Mike. When you have a minute, would you mind explaining the intricacies of the new ApplicationController#set_current_user , and why it’s necessary? I looked through Facebooker’s RDoc and source, but there aren’t many comments to help piece it all together. Thanks! |
|
09 Mar 2009, 13:29
Mike Mangino (543 posts) |
The set_current_user above is just used to find or create a User model for the current facebook session. The complexity comes from storing the session key if necessary. Having the session key allows us to access the REST API outside of a request for about an hour after the user visits our application. This can be useful if you are sending messages using some sort of delayed job API to take them out of the HTTP request flow. |
| You must be logged in to comment |

