Reputation: 12837
I am posting to a page on MY Facebook account from my web site using FBGraph gem but how do I get my access token? I am certain that my code is correct to post to the page I need
def send_fb_message(params = {})
owner = FbGraph::User.me(FB_TOKEN)
pages = owner.accounts
page = pages.detect do |page|
page.identifier == FB_PAGE_ID
end
page.feed!(
:message => params[:message],
:description => params[:description],
:link => params[:link] )
end
As you can see FB_TOKEN is a constant, perhaps it should be a variable but whatever it needs to be I have no idea how to get the value for the access token. (All permissions have been accepted by my facebook account including manage_pages permission.)
I have a secret and an app id for my Facebook app and I'm using the graph api but there seems to be nowhere for me to make use of these.
The app login docs here http://developers.facebook.com/docs/authentication/#applogin don't make it clear to me at all as to how to obtain the access token neither does the docs for the FBGraph gem unless I am missing something?
Is there a better way?
UPDATE
Thank's to the reply from @Lego below I have been able to make this post work using a token using the access token tool https://developers.facebook.com/tools/access_token/. I can see the post if I am logged in as my user but I am unable to see the post if I am not logged in How do I make this post public?
Upvotes: 4
Views: 18642
Reputation: 12082
A workaround would be (but only if nothing else helps!) to ask yourself the offline_access permission and get yourself an access token via the Access Token Tool or the Graph API Explorer. Then you could hardcode the access token into your website (serverside). Since you gave your app the offline_access permission the token should not expire.
Upvotes: 3