Last Updated: February 25, 2016
· blazeeboy

Create a twitter bot using Ruby

i wanted to favourite all tweets that are talking about ruby and rails, that gets some attention to my twitter account.

require 'Twitter' #gem install twitter
while true
        # Create a read write application from : 
        # authenticate it for your account
        # fill in the following
        config = {
            consumer_key:        '',
            consumer_secret:     '',
            access_token:        '',
            access_token_secret: ''
        rClient = config
        sClient =

        # topics to watch
        topics = ['#rails', '#ruby', '#coding', '#codepen']
        sClient.filter(:track => topics.join(',')) do |tweet|
            if tweet.is_a?(Twitter::Tweet)
              puts tweet.text 
              rClient.fav tweet
        puts 'error occurred, waiting for 5 seconds'
        sleep 5


4 Responses
Add your response

Do i need to install any thing before i run this bot?

over 1 year ago ·

twitter gem and create a twitter app with read and write paermissions

over 1 year ago ·

i finally got it! I have installed twitter gem and i am running your codes on terminal. It runs however, it just runs in the back ground and i have no idea what it is doing on twitter.
Please advise

over 1 year ago ·

Here is the message that i get in terminal;

"{:status_code=>401, :header=>{"connection"=>"close", "Cache-Control"=>"must-revalidate,no-cache,no-store", "Content-Type"=>"text/html", "date"=>"Sun, 27 Apr 2014 04:21:46 UTC", "x-connection-hash"=>"d0b88100384f4fbf0c975b00e1147783", "content-length"=>"310"}}
error occurred, waiting for 5 seconds;

BTW thanks for sharing your ruby bot codes :D

over 1 year ago ·