@oauth = Koala::Facebook::OAuth.new(<app_id>, <app_secret>, 'https://site.com/')
code = @oauth.url_for_oauth_code(:permissions => "publish_actions,manage_pages,publish_pages")
=> "https://www.facebook.com/dialog/oauth?client_id=<app_id>&redirect_uri=https%3A%2F%2Fsite.com%2F&scope=publish_actions%2Cmanage_pages%2Cpublish_pages"
Open that url in browser and grant access to app. At the end you will be redirected to your website https://site.com/?code=<access_token>
. Paste access token here:
@oauth.get_access_token_info(<access_token>)
Paste that access token here:
@user_graph = Koala::Facebook::API.new(<access_token>)
Finally get page token:
@graph.get_connections('me', 'accounts').detect { |i| i['id'] === <your_page_id> }['access_token']
Test here:
https://developers.facebook.com/tools/debug/accesstoken/?q=<page_access_token>
It should say:
Expires Never