Forbidden or Bad Request on friend call

0 views
Skip to first unread message

Matt Topper

unread,
Sep 8, 2008, 1:14:52 PM9/8/08
to twitter4r-users
I've been trying for a few hours now to get the friend requests
working with twitter4r. My call is pretty simple

friend = 'topperge'
api = Twitter::Client.new( :login => username, :password => password)
api.friend(:add, friend)

If I use 0.3.0 I get a Bad Request message back and using the
development 0.3.1 I get a Forbidden error back from twitter.

All my replies and normal status changes work successfully, just
nothing on the friend api. I've also checked my rate limits and have
plenty.

Matt

SP

unread,
Sep 9, 2008, 2:10:14 AM9/9/08
to twitter4r-users
Hi Matt,

The responses you are getting are because the user you are executing
as is already a friend of 'topperge'. I have this on the todo list to
raise a more appropriate exception instead of a Forbidden.

If you do the following around friend(:add, ...) or friend(:remove,
....) calls on the client you can cater for these cases:

begin
client.friend(:add, supposed_new_friend)
rescue Twitter::RESTError => re
unless re.code == "403"
# put code to handle case where Forbidden error is not raised
because you probably shouldn't ignore that case
end
end

The same is true when you are trying to do a friend(:remove, ....) on
a username that you are not already friends with. Right now Twitter4R
library only returns exactly what the Twitter.com API returns, but as
I said earlier this is on the todo list to for me to tidy up the
library after I reorganize the code a little.

Thanks and hope this helps and explains the issue,
Susan
Reply all
Reply to author
Forward
0 new messages