【问题标题】:Ruby on Rails Facebook Graph API OAuth error #506 Duplicate status messageRuby on Rails Facebook Graph API OAuth 错误 #506 重复状态消息
【发布时间】:2011-12-12 18:17:32
【问题描述】:

我有一个发布到 Facebook 的 Rails 应用程序。我进行了救援以防止两次发布相同消息的错误。我想让我的应用程序只通知用户并继续,但我似乎无法挽救这个错误。

这是我的代码:

begin
  current_user.facebook.feed!(:message => 'THIS IS A TEST PLEASE IGNORE::Hello, Facebook!')
rescue FbGraph::Unauthorized
  flash[:alert] = "Already Posted"
end
redirect_to show(@track)

我使用此代码得到的错误是:

OAuthException :: (#506) 重复状态消息

【问题讨论】:

    标签: ruby-on-rails facebook-oauth rescue


    【解决方案1】:

    当您收到 OAuthException 错误时,为什么要从 FbGraph::Unauthorized 中进行救援?

    begin
      current_user.facebook.feed!(:message => 'THIS IS A TEST PLEASE IGNORE::Hello, Facebook!')
    rescue OAuthException
      flash[:alert] = "Already Posted"
    end
    redirect_to show(@track)
    

    【讨论】:

    • 我无法让它与 OAuthException 或 Exception::OAuthException 一起使用。他们说未知异常,但我只是拯救了所有异常
    【解决方案2】:

    试试:

    begin
      current_user.facebook.feed!(:message => 'THIS IS A TEST PLEASE IGNORE::Hello, Facebook!')
    rescue => e
      if(e.fb_error_type == "OAuthException" 
       flash[:alert] = "Already Posted"
      end
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-28
      • 1970-01-01
      • 2021-12-04
      • 2011-07-05
      • 1970-01-01
      • 1970-01-01
      • 2015-03-03
      • 1970-01-01
      相关资源
      最近更新 更多