The following code is a ruby version of “auto-follow” script introduced in the previous post: How to Auto Follow on Twitter by Twitter API & PHP.
Whole Code for Twitter Auto-Follow
#!/usr/bin/ruby require 'rubygems' require 'twitter' USERNAME = 'your_twitter_username' CONSUMER_KEY = 'your_consumer_key' CONSUMER_SECRET = 'your_consumer_secret' OAUTH_TOKEN = 'your_oauth_token' OAUTH_TOKEN_SECRET = 'your_oauth_token' client = Twitter::Client.new( :consumer_key => CONSUMER_KEY, :consumer_secret => CONSUMER_SECRET, :oauth_token => OAUTH_TOKEN, :oauth_token_secret => OAUTH_TOKEN_SECRET ) follower_ids = [] client.follower_ids(USERNAME).each do |id| follower_ids.push(id) end friend_ids = [] client.friend_ids(USERNAME).each do |id| friend_ids.push(id) end client.follow(follower_ids - friend_ids)
How to Execute
Copy & paste the code above to a file and save it as auto_follow.rb
.
Note that you need The Twitter Ruby Gem, which is a Ruby interface to the Twitter API. You can install it with gem
command.
$ gem install twitter
After install, the auto-follow script in Ruby will work as it should.
$ ruby auto_follow.rb
please help. API has been changed to API v 1.1, but my site didn’t work.
Are you using the version 4 of the ruby twitter gem (https://github.com/sferik/twitter)?
The version 4 of this library targets Twitter API v1.1 and works fine.