views:

678

answers:

2

I'm trying to user Facebooker to publish stories to Facebook. When a user submits a form on my site, I'm using fb_user_action to show the dialog asking if a story can be published. When that is dismissed, I want to redirect to a different page.

Facebook's documentation for showFeedDialog talks about the continuation parameter. It takes a JavaScript function that will be called after the dialog is dismissed. I can't get that function to be called.

<script language="javascript">
var continuation = function () {
  location.href = 'http://target-url.com';
}
</script>

<% init_fb_connect "XFBML","Api" do %>
  <%= fb_user_action(@action, @message, @prompt, 'continuation') %>
<% end %>

Everything works perfectly except the continuation function doesn't get called. Any suggestions for what I'm doing wrong?

A: 

Ok, I've never used Ruby in my life, but something about that Facebooker call looks wrong to me. Here's what fb_user_action looks like from your link:

def fb_user_action(action, user_message = "", prompt = "", callback = nil)
  update_page do |page|
    page.call "FB.Connect.showFeedDialog",action.template_id,action.data,action.target_ids,action.body_general,nil,page.literal("FB.RequireConnect.promptConnect"),callback,prompt,user_message
  end
end

So, based on what I looked up about page.call, that looks to me like it will generate javascript like this:

FB.Connect.showFeedDialog(template_id,data,target_ids,body_general,nil,promptConnect,callback,prompt,user_message);

However, the signature of showFeedDialog is:

FB.Connect.showFeedDialog(template_id,data,body_general,target_ids,callback,prompt,user_message)

The order of the parameters that the Facebooker fb_user_action function is generating for the Javascript seems completely wrong to me. The callback parameter looks like it would instead be replaced by a nil, so nothing would ever get called.

What if instead of calling fb_user_action, you just used page.call yourself, but with the parameters in the right order?

Again, I could be failing to understand the page.call and/or Ruby syntax here. But I'd double-check that Facebooker function, as the FB API changes all the time.

zombat
+2  A: 

I just dug into this more. I believe this is a Facebooker bug. I had to wrap the callback parameter in a page.literal call. The modified method that works is below:

def fb_user_action(action, user_message = "", prompt = "", callback = nil)
  update_page do |page|
    page.call "FB.Connect.showFeedDialog",action.template_id,action.data,action.target_ids,action.body_general,nil,page.literal("FB.RequireConnect.promptConnect"),page.literal(callback),prompt,user_message
  end
end

I'll follow up with the Facebooker developer to try to get this fixed in a future version.

Algorithmic
This has been fixed in Facebooker and should be available in the next release.
Algorithmic