Search code examples
ruby-on-railsfacebook-oauthrescue

Ruby on Rails Facebook Graph API OAuth error #506 Duplicate status message


I have a Rails application that is posting to Facebook. I put a rescue to prevent the error of posting the same message twice. I would like to have my app just notify the user and move on, but I cannot seem to rescue this error.

This is my code:

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)

The error I get with this code is:

OAuthException :: (#506) Duplicate status message


Solution

  • Why are rescuing from FbGraph::Unauthorized when you're getting an OAuthException error?

    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)