How to post a message to the Facebook wall with OmniAuth/Devise

Tagged facebook, omniauth, devise  Languages ruby

In your OmniAuth/Devise-callback controller add this line:

session['fb_access_token'] = omniauth['credentials']['token']

This will save the auth_token, which we’ll need for accessing the Facebook API.

Next, in your Devise initializer, usually config/initializer/devise.rb, request additional permissions:

config.omniauth :facebook, 'heh', 'lol', :scope => 'publish_stream,email,offline_access,manage_pages'

The offline_access permission means you can use the token even if the user logs out.

Now if a user logs in you’ll have access to the user’s Facebook access_token, which can be used to post to his wall.

api_key = 'heh'
api_secret = 'lol'

client =, api_secret, :site => '')
token =, session['fb_access_token'])'/me/feed', :message => "testing")

To understand how it all works, read about Facebook permissions, the Graph API and the documentation on the post command.

Getting the Access Token

You can also use this URL to get a permanent access_token:<app_key>&client_secret=<app_secret>

Posting links

Use to post links.

Posting to a page

When posting to a page you need to change "me" to the page name:'/acmexxx/post', :message => "testing")

If you need to post to the page as the page itself, not the admin user, you need to get the access_token for the page.

First you need to add the manage_pages permission:

config.omniauth :facebook, 'heh', 'lol', :scope => 'publish_stream,email,offline_access,manage_pages'

You should now login as the page admin and get a new access_token, which you can then use to get a list of accounts and pages you are the administrator for:<admin_access_token>

You should see the access_token for each page listed in the response, use it to post to the page as the page.