How to use fb_graph gem to post from app on my page wall?

二次信任 提交于 2019-12-08 05:34:21

问题


Ok, so fb_graph looks pretty simple to use but Im kinda confused as how to use it.

All I want to do, and when I post a blog entry from my rails app, have the app automatically post to my facebook page.

I have my facebook app_id and app_secret already but Im confused as to what to do with this code:

me = FbGraph::User.me(ACCESS_TOKEN)
me.feed!(
  :message => 'Updating via FbGraph',
  :picture => 'https://graph.facebook.com/matake/picture',
  :link => 'https://github.com/nov/fb_graph',
  :name => 'FbGraph',
  :description => 'A Ruby wrapper for Facebook Graph API'
)

How do I get that ACCESS_TOKEN? And how do I make sure my posts are going to my fan page and not my personal facebook wall?

Lastly, where does the above code go since I want to post when a blog entry is posted should that code go in the controller under "new" or should it be a method called in the model whenever a blog post is made?


回答1:


You should take a look here : Where do I get an access token from to post to my facebook page using FBGraph gem in Rails 3?

It seems that you can generate tokens here :

  • https://developers.facebook.com/tools/access_token/
  • https://developers.facebook.com/tools/explorer/

This links may help too : Error with facebook access token




回答2:


For the second half of your question: It's likely you want the code to send to Facebook in your model. You can add an after_create callback - this'll fire when the model is first created and saved.

Two things to watch for though - Facebook is an external service, and might be down, slow or send errors back to your app. So, make sure to catch exceptions that might be thrown, or, ideally, use a background job to process the posting.



来源:https://stackoverflow.com/questions/9847192/how-to-use-fb-graph-gem-to-post-from-app-on-my-page-wall

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!