How to: merge facebook connect dialog with successive request dialog for extended permissions
When using the Facebooker plugin for connecting your Rails app with Facebook, it’s simple by using the method fb_login_button and providing a callback url.
Since quite sometime, Facebook has restricted the open accessibility of the user’s stream via API even when the user is connected via Facebook Connect. And it requires another permission from the user where user allows your app for the specifically asked permissions.
In case if out Rails app is required to read the user’s stream, including photos, posts, news and profile etc and also your app will write onto the wall of the user and pushing new status messages, we need to implement the request permissions dialog.
Now it makes all the sense to have the dialog appear successive to when the user connects via Facebook Connect dialog.
Tow main permissions needed for the purpose above are:
- publish_stream
- read_stream
and then needs to be sent as an array.
For more details on all the available permissions and extended permissions you can visit the Facebook docs page here http://developers.facebook.com/docs/authentication/permissions
Here is how we can implement the successive merger of the two dialog boxes by creating a helper method so it can easily be used anywhere in the application.
Create a method fb_login_button_with_permissions in the file app/helpers/application_helper.rb like this:
def fb_login_button_with_permissions(options={})
options = {:result_url => "/facebook_connect", :permissions => 'publish_stream,read_stream'}.update(options)
fb_login_button("javascript:FB.Connect.showPermissionDialog('#{options[:permissions]}', function(perms){window.location='#{options[:result_url]}';})")
end
PS: here “/facebook_connect” is your callback url which handles the creation of Rails Application’s session for the Facebook Connected user etc. It can vary depending on how you implemented and name you gave.
Now in your views you can call the method for showing the Facebook Connect button
<%= fb_login_button_with_permissions %>
And this should pop up the dialog box for requesting extended permissions after connecting through the Facebook Connect dialog.
Tags: facebook, rubyonrails

[...] How to: merge facebook connect dialog with successive request dialog for extended permissions 31 Jul [...]