Follow your Followers using Ruby

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

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


6 Comments 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.

  2. 2 Money Man said at 3:45 am on May 13th, 2010:

    How do you make money auto racing legally?

  3. 3 mobilekarta said at 3:42 pm on May 30th, 2010:

    I join. It was and with me. Let’s discuss this question.
    Certainly. I agree with told all above.
    It doesn’t matter!
    Excuse, that I interrupt you, but, in my opinion, there is other way of the decision of a question.
    Remarkably! Thanks!

    from http://mobilekarta.ru

  4. 4 mototehnika said at 5:22 am on June 15th, 2010:

    Will money be taken from my taxes because I have a student loan?

  5. 5 kvadrocikly said at 5:07 pm on June 20th, 2010:

    When you order frogs legs at a restaurant – what do they do with the rest of the frog ?

  6. 6 Laura Bartkiewicz said at 4:40 pm on June 22nd, 2010:

    I’m looking for an experienced Ruby on Rails developer in Burlington, MA Area. I’d love to speak to whoever’s interested, I’ve been searching for a while. Below’s the job description, please let me know if you’re interested! Thanks!

    Job Description: Ruby on Rails Developer needed for a long term contract.

    Position requirements:

    * 2+ years experience with Ruby on Rails
    * 5+ years prior experience as a Java Developer with a strong software engineering/middle-tier background
    * Open Source Tools experience
    * Database experience (ideally MySQL)
    * Ruby on Rails testing experience is a plus

    They have 4 primary projects they need help with. Depending on background, consultant could work on any of the 4


Leave a Reply