I am using Rails 3 + fb_graph to post to my own Facebook page. I have code that works, but it uses an access token that only works for a couple of hours. And it is very annoying to refresh this access token a couple of times a day. So I registrated for a FB app. I now have:
my_app = FbGraph::Application.new("App ID");
acc_tok = my_app.get_access_token("App Secret");
me = FbGraph::User.me(acc_tok)
me.fetch
me.accounts
account = me.accounts.select {|account| account if account.name == "BoaJobs.com"}.first
page = FbGraph::Page.new(account.identifier)
note = page.note!(:access_token => account.access_token, :subject => @title, :message => @message, :link => @url)
But I am getting an error on the me.fetch line:
OAuthException :: An active access token must be used to query information about the current user.
Can somebody post some code that helps me solve this problem. Thank you very much in advance.
ill refer you to https://github.com/nov/fb_graph/wiki/Page-Management
where nov states: You need the page’s access token to manage your page.
Your (an user’s) access token doesn’t work here.
follow his link to the facebook developers site for more info
you’ll need the users access_token and i do this through omniauth-facbook https://github.com/mkdynamic/omniauth-facebook
which you retrieve the use by first inputting this initializer into your app
(note you can change the permissions on the scope here check facebook developers login permissions for more
there are some inner workings to omniauth and omniauth-facebook but the jist is
when you get the callback from facebook you have a rack omniauth hash from the request
from that has you can access the users access token like this
you can then feed that token into your fb_graph page call
you will then simply be able to create a note by calling your desired method without a reference to the access token