Its always tricky to post on the wall of the FB Page. It requires PAGE_ID and ACCESS_TOKEN (Not the user’s access token) and so many questions on how to get facebook page id and access token.
The FB Developers webapp way
First create a page by visiting http://www.facebook.com/pages/create.php?ref_ type=sitefooter But this is optional. If you’ve already created the page, the just skip this part.
- Create an App
- Created App admin page
- Graph API Explorer
- Get Access Token
In the Extended Permissions tab, select manage_pages and publish_stream and click Get Access Token
- Authorize you account
- Allow Permission
- Copy the blue-highlighted temporary access token
- Permanent Access Token
The above temporary access token is also valid. But its limited to 60 days. Its better to have the permanent access token so that it works in the long run, though I forget to updated periodically.
To get this, go the following url replacing the TEMPORARY_ACCCESS_TOKEN value with the temporary access token.
- First we need to get the PAGE_ID of the page. To get this, visit https://www.facebook.com/pages/
And on the left sidebar under Pages section, select the page.
- Copy the Page id from the address bar
- Here I’m using the fb_graph gem
require ‘rubygems’ require ‘fb_graph’ require ‘pry’ FbGraph.debug!
PAGE_ID = “349835561791721” YOUR_ACCESS_TOKEN = “……”
owner = FbGraph::User.me(USER_ACCESS_TOKEN) pages = owner.accounts
page = pages.detect do |page| page.identifier == PAGE_ID end
There is the page access_token