Twitter4R v0.2.0: Friendship API

Written on 8:15:00 AM by S. Potter

After a week I realized I had not yet written about the Friendship API in Twitter4R and it is one of the simpler the parts of the core library. Below shows some code to add and remove a friend:

gem('twitter4r', '>=0.2.0')

client = => 'mylogin', :password => 'mypasswd')
# we can add a friend by using their unique integer id or user object.
screen_name = 'myfriend'
user = Twitter::User.find(screen_name)
id =

# Like any of the following....
client.friend(:add, user)
client.friend(:add, id)

# We can also use any of the following APIs to do exactly the same thing...
client.friend(:remove, user)
client.friend(:remove, id)
See related Twitter4R RDoc.

If you enjoyed this post Subscribe to our feed

1 Comment

  1. Anonymous |

    Is there a way that I can 'request' to be added to follow someone? I have an instance, where users opt to follow my app and I then auto follow them back (using a cron job and Twitter4r) - however, a number of users are 'protected' and I have to 'request' to be added. Either that or if there's a way that I can filter (and to know) that I've been forbidden from following them, I can send them an appropriate message?




Post a Comment