I have an FB account and i have created a fan page for my club and few other pages as well. I have an app in Ruby on Rails. I want to publish some feed on my club fan page. How can i do this? I have been using Koala Gem and able to successfully post to my wall but not on to the page. I want to access the list of all the fan pages associated with my account instead of giving the name of specific page.
here is my simple method which i am using to communicate to FB Graph API.
def facebook
@facebook ||= Koala::Facebook::GraphAPI.new(oauth_token)
rescue Koala::Facebook::APIError => e
logger.info e.to_s
nil # or consider a custom null object
end
Answer submitted by Sumit can be an approach but after searching around some more forums, finally i got an elegant way to do it.
@user_graph = Koala::Facebook::API.new(user_access_token)
pages = @user_graph.get_connections('me', 'accounts')
# get access token for first page
first_page_token = pages.first['access_token']
# or: retrieve access_token for a given page_id
page_token = @user_graph.get_page_access_token(page_id)
Passing on the "accounts" parameter to get_connection worked elegantly for me. Here is the reference to API.
And one last thing, never forget to add the "manage_pages" permission in your permissions list.