qotqqq
Last Updated: February 25, 2016
·
2.909K
· blazeeboy
12715527 10153407351782957 5557639479013711635 n

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
    begin
        # Create a read write application from : 
        # https://apps.twitter.com
        # authenticate it for your account
        # fill in the following
        config = {
            consumer_key:        '',
            consumer_secret:     '',
            access_token:        '',
            access_token_secret: ''
        }
        rClient = Twitter::REST::Client.new config
        sClient = Twitter::Streaming::Client.new(config)

        # 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
            end
        end
    rescue
        puts 'error occurred, waiting for 5 seconds'
        sleep 5
    end

end
Say Thanks
Respond

4 Responses
Add your response

14271
B817a41a9eba5bd2543e82935ed85394

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

over 1 year ago ·
14272
12715527 10153407351782957 5557639479013711635 n

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

over 1 year ago ·
14288
B817a41a9eba5bd2543e82935ed85394

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 ·
14289
B817a41a9eba5bd2543e82935ed85394

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 ·