I was able to solve this problem using some code I found in the
facebooker_mq plugin - http://rubyforge.org/projects/facebooker-mq/
First, I create a session object, which is re-used for each user that
needs a message sent:
session = Facebooker::CanvasSession.create(
ENV[ ''FACEBOOK_API_KEY'' ], ENV[
''FACEBOOK_SECRET_KEY'' ] )
Then, for each user being notified, if I''ve stored an infinite session
key for them, I secure the session (I only store the session keys if
they''re infinite, so the expires parameter at the end is always 0):
session.secure_with!( currentUser.infinite_session,
currentUser.id, 0 )
Once that is done, the session key can be used normally (at least for
the one call I''m making send_email).
The other thing I did, just to make sure this doesn''t mess up
"normal"
operation, was to move the background tasks into their own controller.
I did not have this new class extend the ApplicationController class,
because it doesn''t render any pages and so isn''t a true Rails
controller. I''m not totally sure, but I think its possible this code
could be run out of a class in the lib directory (or a model class, if
that were more appropriate for someone else''s app).
If there''s a better way to solve this problem, I''d be
interested in
knowing about it.
Thanks!
Mark
On Feb 24, 2008, at 5:09 PM, Mark Slater wrote:
> I''m setting up a recurring (cron) task to trigger a method in my
> facebook controller. The point is to find all users that need to
> receive notification emails and send those messages off (every few
> hours, and only if they haven''t been sent already...
don''t want to be
> spammy).
>
> I''ve got infinite session keys for the users (at least for the
ones
> who will be receiving email notifications), but I don''t know how
to
> create a Facebooker session from those. I tried calling
> set_facebooker_session, but got this error:
>
> undefined local variable or method `set_facebook_session'' for
> FacebookController:Class
>
> So it seems that the script/runner isn''t loading the facebooker
> plugin? Which doesn''t make much sense, because the facebooker YML
> config file is being processed, and that wouldn''t happen if the
plugin
> didn''t get loaded. What am I missing here? Is there a better way
to do
> recurring background notification tasks with facebooker?
>
> Thanks!
>
> Mark
> _______________________________________________
> Facebooker-talk mailing list
> Facebooker-talk at rubyforge.org
> http://rubyforge.org/mailman/listinfo/facebooker-talk