Encountering 406 error with Facebooker API on updated Rails version

Hey everyone, I’m having trouble with my Rails app after upgrading. It was running smoothly on Rails 2.2 with Facebooker 1.0.13, but now I’m getting a 406 error on Rails 2.3. Strangely, this issue only occurs when I access the app through Facebook’s iframe; outside of Facebook everything runs fine.

I’ve checked the MIME type settings and the canvas/iframe configuration in Facebook. Has anyone experienced a similar problem? I’m wondering if there has been a recent change in the Facebook API or if there’s a quick fix available in Facebooker.

Here’s a snippet from my dev log:

Processing PostsController#index [GET]
Parameters: {
  "fb_sig_app_id": "12345",
  "fb_sig_in_iframe": "1",
  "fb_sig_locale": "en_US",
  ...
}
Completed in 135ms | 406 Not Acceptable

Any ideas on what might be causing this? I would really appreciate your help!

hey noah, had similar headache upgrading. try adding this to ur application controller:

before_filter :set_fb_mime_type

def set_fb_mime_type
request.format = :html if fb_in_canvas?
end

this fixed it 4 me. gl!

I’ve dealt with this exact issue before. The problem likely stems from Rails 2.3 handling MIME types differently than 2.2. A quick fix is to modify your application_controller.rb file. Add this method:

def set_p3p_header
response.headers[‘P3P’] = ‘CP=“CAO PSA OUR”’
end

Then call it with a before_filter in your controller:

before_filter :set_p3p_header, :only => [:your_action]

This sets a P3P header which Facebook requires for proper iframe integration. It solved the 406 error for me without needing to change content types or other configurations. Give it a try and let us know if it works for you.

I encountered a similar issue when upgrading my Rails app with Facebooker integration. The 406 error usually indicates a mismatch between the content type expected by the client and what the server is trying to send.

In my case, the problem was related to how Rails 2.3 handles mime types differently from 2.2. I resolved it by explicitly setting the content type in my controller actions that were being called within the Facebook iframe.

Try adding this line at the beginning of your controller actions:

response.headers[‘Content-Type’] = ‘text/html; charset=utf-8’

This forces Rails to send the correct content type header, which should satisfy Facebook’s iframe requirements.

Also, double-check your Facebooker configuration file to ensure all settings are compatible with the new Rails version. Sometimes, subtle changes in config syntax can cause unexpected behavior.

If that doesn’t work, you might want to consider updating to a more recent version of Facebooker or exploring alternative gems that are actively maintained for newer Rails versions. The Facebook API has changed significantly over the years, and older gems may not keep up with these changes.