Rails post to facebook page

I have a rails app that I wish to be able to post to a fb page. I understand Koala is the gem that facilitates this functionality.

I have created a facebook app and have an app_id & app_secret.

Can my facebook app post to a page or does it need to be done by a page admin?

Application Access Tokens

Facebook applications can also get their own access tokens, which can be used to manage realtime updates and perform certain other sessionless activities. To get your app's access token, just run:

@oauth = Koala::Facebook::OAuth.new(app_id, app_secret)
@oauth.get_app_access_token 

https://github.com/arsduo/koala/wiki/OAuth

Edit 1 From: https://github.com/arsduo/koala/wiki/Acting-as-a-Page and https://developers.facebook.com/docs/facebook-login/access-tokens/ I understand I will need to obtain an access token and then a page token:

@user_graph = Koala::Facebook::API.new(user_access_token)
pages = @user_graph.get_connections('me', 'accounts')
page_token = @user_graph.get_page_access_token(page_id)
@page_graph = Koala::Facebook::API.new(page_token)
@page_graph.get_object('me') # I'm a page
@page_graph.get_connection('me', 'feed') # the page's wall
@page_graph.put_wall_post('post on page wall') # post as page, requires new publish_pages permission
@page_graph.put_connections(page_id, 'feed', :message => message, :picture => picture_url, :link => link_url)

All of the above is self explanatory however I am stuck on one fundamental being how should my rails app obtain a user_access_token. As I want all of the posting to be performed by my rails app "as a page" I would imaging this user_access_token should be set as a constant once in the rails app and not requested every time the rails app needs to post.

The koala home page states this is possible: Configuration

Most applications will only use one application configuration. Rather than having to provide that value every time, you can configure Koala to use global settings:

# In Rails, you could put this in config/initializers/koala.rb
Koala.configure do |config|
  config.access_token = MY_TOKEN
  config.app_access_token = MY_APP_ACCESS_TOKEN
  config.app_id = MY_APP_ID
  config.app_secret = MY_APP_SECRET
  # See Koala::Configuration for more options, including details on how to send requests through
  # your own proxy servers.
end

https://github.com/arsduo/koala

As I have the app_id and app_secret I am still unsure of how to obtain the access_token and app_access_token required above.

Yes, I am lost.

Edit 2 As the user_access_token expires I am confused as to how this can be hard coded into koala.rb?

链接地址: http://www.djcxy.com/p/32672.html

上一篇: Instagram是否在2018年3月30日更改API率限制?

下一篇: Rails发布到Facebook页面