Facebook发布帮助,每当用户创建帖子时添加到Facebook

时间:2011-03-29 23:15:14

标签: ruby facebook ruby-on-rails-3 methods facebook-graph-api

我认为这个问题是编写好的红宝石代码,让我看看你们的想法。我已经使用omniauth和fbgraph设置了所有auth / access令牌的东西,我似乎无法解决的是如何在用户创建帖子时集成它。

我的应用程序围绕用户发帖(由“标题”和“内容”组成),我希望帖子在Facebook或Twitter或两者上自动共享,具体取决于用户设置的特定身份验证。如果用户在没有facebook / twitter的情况下按常规方式注册,则不在任何地方共享。

如果用户的帖子自动发布,我将如何整合动态方式来分享用户帖子的标题和内容?我正在考虑某种类型的post_save到post模型,但我无法让它正常工作。感谢您的帮助,非常感谢。如果我想在以后分享链接和图片时,如果它是一种允许扩展的方法,那就太棒了。

这是搜索中唯一一个关于分享这两个问题的帖子,但我仍然感到困惑:( Easy way of posting on Facebook page (not a profile but a fanpage)

1 个答案:

答案 0 :(得分:0)

Post模型中:

after_commit :share_content

def share_content
  user.share_content title, content
end

然后在User模型中有:

def share_content title, content
  # some conditionals with whatever stuff you have to determine whether
  # it's a twitter and/or facebook update...

  if go_for_twitter
    twitter.update title
  end

  if go_for_facebook
    facebook.feed! :message => title
    # ...etc.
  end
end