Follow your followers in Ruby


/ Published in: Ruby
Save to your folder(s)



Copy this code and paste it in your HTML
  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

URL: http://www.flyingmachinestudios.com/2009/05/20/follow-your-followers-using-ruby/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.