Follow your Followers using Ruby

Posted: May 20th, 2009 | Author: Daniel Higginbotham | Filed under: Uncategorized |

I have the following in a rake task run every 30 minutes. You’ll need jnunemaker’s twitter gem.

Follow your followers in Ruby

  1. require 'twitter'
  2. # Check out the twitter gem docs for using oauth
  3. httpauth = Twitter::HTTPAuth.new("username", "password")
  4. base = Twitter::Base.new(httpauth)
  5. to_follow_ids = base.follower_ids - base.friend_ids
  6. unavailable_count = 0
  7. to_follow_ids.each do |tfid|
  8.   begin
  9.     base.friendship_create(tfid, true)
  10.   rescue Twitter::General
  11.     # Twitter::General is raised for 403 errors
  12.     # Which occur when you're trying to follow someone who's been banned by twitter
  13.     base.block(tfid)
  14.   rescue Twitter::Unavailable
  15.     # Wait and try again if twitter's telling you to wait
  16.     sleep 5
  17.     if unavailable_count < 3
  18.       retry
  19.       unavailable_count += 1
  20.     end
  21.   end
  22. end


One Comment on “Follow your Followers using Ruby”

  1. 1 Furaelula said at 3:29 am on June 1st, 2009:

    Good afternoon! Escort Model information there. sex men. I am pleased to welcome you to its website, prostitutes Kiev - Fish. You can visit my blog.


Leave a Reply