【问题标题】:Facebook posting help, adding to facebook whenever a user creates a postFacebook 发布帮助,每当用户创建帖子时添加到 facebook
【发布时间】:2011-07-25 16:51:28
【问题描述】:

我认为这个问题是关于编写漂亮的 ruby​​ 代码的问题,让我看看你们的想法。我已经用omniauth和fbgraph设置了所有的身份验证/访问令牌,我似乎无法解决的是如何在用户创建帖子时集成它。

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

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

这是搜索时唯一能阐明分享给双方的帖子,但我仍然感到困惑 :( Easy way of posting on Facebook page (not a profile but a fanpage)

【问题讨论】:

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


    【解决方案1】:

    在您的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
    

    【讨论】:

      猜你喜欢
      • 2023-03-24
      • 2020-02-17
      • 1970-01-01
      • 1970-01-01
      • 2013-08-30
      • 2012-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多