views:

1617

answers:

5

I have an existing Rails web application which I would like to integrate with Facebook, so that when the user takes actions in my application news items containing external links are later posted to the users wall / feed by a daemon which summarises the latest activity. I don't need single signon etc. at present, just the ability to send updates.

I would also like to be able to send notifications to the user's friends if they are also using the app, but I'd be happy with just the news feed functionality.

I'm working off the pragmatic programmer's book Facebook Platform Development by Michael Mangino, which uses the facebooker plugin, and early on the book says this:

Facebook uses sessions to verify that our application is performing actions on behalf of an active user. When we want to send a notification on behalf of our user, we will provide Facebook with that user’s session information. Facebook will verify that the session does in fact belong to the requesting user and will also verify that the user has been active on our application within the past hour. Facebook uses the session to prevent applications from taking action on behalf of a user who isn’t actively using them

What counts as 'being active in the application' and what does it mean in this context? I have seen other apps that do things like automatically publish RSS feeds to a user's profile so it does seem to be possible to have similar apps where the only interaction is a one-off install and configure.

How do these apps work and is it possible to get at this functionality from facebooker?

+1  A: 

You have to prompt the user for the "publish_stream" extended permissions. After this is complete you will be able to publish to user's streams who have your app added and accepted these extended permissions. http://wiki.developers.facebook.com/index.php/Extended_permissions

Then use the Facebooker::User.publish_to. Also to send notifications see Facebooker::Session.send_notification (this does not require any extended permissions)

Since 99% of the documentation I have seen for facebooker and the facebook API in general, seems to all deal with active sessions and a lot of it within the canvas. Haven't really seen much about doing all this from the backend.

So basically with facebooker, since you aren't within the canvas, you have to create your own Facebooker::Session and Facebooker::User.

fbsession = Facebooker::Session.create(api_key, secret_key)
fbuser = Facebooker::User.new(<Facebooker user id>, fbsession)

#requires "publish_stream" extended permission
fbuser.publish_to(fbuser, :message => "This is a post")

fbsession.send_notification(fbuser.id, "<fb:fbml>some sweet fbml</fb:fbml>")

Hope this helps you out some.

AdamB
thanks, that really helps. But when you say 'prompt the user for extended permission', what does that prompting? The app that the user adds? Does it matter if they subsequently don't log in to the app or if they are not logged into FB?
frankodwyer
hmm and that 'publish_stream' permission seems very wide ranging .e.g. can change status - seems like a lot of privs to have to ask for just to stick a message in the news feed?
frankodwyer
Facebook makes it a pain to do anything with your app users. This is simply prompting for an extra permission that your app has to its user. This permission is saved on facebook's side and all you need to do is save the facebook user id of your app user. This also only needs to be completed once.I use the facebook connect javascript API to prompt for extended permissions, but you can also just do it with a url. Facebooker::Session.permission_url('publish_stream') will return a url a user would have to click and accept. http://facebooker.rubyforge.org/classes/Facebooker/Session.html#M000273
AdamB
A: 

After trying this code I got Permission Error. Can you please tell me, how do I enable publish_stream permissions?

Thank you very much

smithystar
A: 

I'm in a similar situation...here are my current findings. Hope they help.

To obtain the url that a user must click to grant publish_stream access

facebook_session = Facebooker::Session.create
facebook_session.permission_url('publish_stream')

To then post a message to a user's profile

facebook_session = Facebooker::Session.create
facebook_session.post 'facebook.stream.publish', :uid => [UID], :message => 'test'

I'm sure that the above method has limitations, but it's late, I'm tired, and I'll pick it back up in the morning. :-)

Eric M.
A: 

Can somebody tell me how to put media like a Picture in there?

kb
+1  A: 
user = session[:facebook_session].user
user.publish_to(user, :message => "action!",
                            :attachment => {:name => "name of attachment",
                                            :href => "http://link.where.attachment.description.should.link.to",
                                            :media => [{:type => "image",
                                                        :src => "http://link.to.where.attachment.is",
                                                        :href => "http://link.where.attachment.description.should.link.to"}]},
                            :action_links => [{:text => 'Action Link Title',
                                               :href => 'http://www.action.link'}])
Pedro