0

Just today I've found my fbgraph implementation has started returning a 400 Bad Request error which is causing an internal server error.

The controller looks like:

def fb
    fbclient = FBGraph::Client.new(:client_id => 'ID', :secret_id => 'SECRET')
    @fbname = fbclient.selection.user('129220333799040').feed.info!['data'][0].from.name
    @fbmessage = fbclient.selection.user('129220333799040').feed.info!['data'][0].message
end

How can I check before calling @fbname in my view that I've received a 200 status?

Thanks.

Update: following Devin M's suggestion, I've switched the above action to

def fb
        fbclient = FBGraph::Client.new(:client_id => 'ID', :secret_id => 'SECRET')
        begin
            @fbname = fbclient.selection.user('129220333799040').feed.info!['data'][0].from.name
            @fbmessage = fbclient.selection.user('129220333799040').feed.info!['data'][0].message
        rescue
            @fbname = "Facebook Account"
            @fbmessage = "Facebook's API is a nightmare"
        end
    end
2
  • 1
    i think you should check first if you got the user right(fbclient.selection.user('129220333799040')) there are too many chains on your call that might bring about a nil or a 400 bad request. try doing it step by step and add the appropriate check when you find which returns the 400 Commented Jun 4, 2011 at 4:12
  • @corroded - thanks. It seems the api may have changed. I can still access the user, but trying to access the user's feed results in the 400 error Commented Jun 4, 2011 at 4:23

1 Answer 1

1

I think that you should write some tests for this, Its hard to work with Facebooks nightmare of an API. Although if you wanted to catch this error try using that way you can catch the specific error and take some action on it in the rescue portion.

begin
rescue
end

If you want me to take a look at the docs and see what you should catch let me know.

Sign up to request clarification or add additional context in comments.

2 Comments

Ahh, thanks, this works. I was trying to use rescue_from, but that was failing. I have no idea why the sudden errors. It was working as recently as 2 days ago, and a different application is able to use very similar code without an error now... i'll edit my question with what I've used
No problem, Facebook is tough to program against.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.