Skip to content

Instantly share code, notes, and snippets.

@nilsding
Created September 14, 2014 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nilsding/834c2fe8829d29b79e23 to your computer and use it in GitHub Desktop.
Save nilsding/834c2fe8829d29b79e23 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# bot.rb - simple Twitter retweet bot
# See also: http://blog.nilsding.org/blog/2014/09/14/retweetbot-tutorial/
#
# code (c) 2014 nilsding
# License: WTFPL
require 'twitter'
retweet_tags = ["#nilsding", "Fuchs"] # the tags the bot should retweet
client = Twitter::REST::Client.new do |config|
config.consumer_key = "APIKeyGoesHere"
config.consumer_secret = "APISecretGoesHere"
config.access_token = "29952844-AccessTokenGoesHere"
config.access_token_secret = "AccessSecretGoesHere"
end
streamer = Twitter::Streaming::Client.new do |config|
config.consumer_key = "APIKeyGoesHere"
config.consumer_secret = "APISecretGoesHere"
config.access_token = "29952844-AccessTokenGoesHere"
config.access_token_secret = "AccessSecretGoesHere"
end
streamer.filter(track: retweet_tags.join(",")) do |object|
if object.is_a? Twitter::Tweet # it's a tweet!
retweet_tags.each do |tag| # double-check if the tweet actually contains the retweet tag
if object.text.downcase.include? tag.downcase
# uncomment the next line if you want to see the retweeted tweet
# puts "#{object.user.screen_name}: #{object.text} (#{object.id})"
client.retweet object.id
break
end
end
end
end
@unixproject
Copy link

[mg@nilzomania mixbot]$ ruby other_retweet_bot.rb
/home/menog/.gem/ruby/2.4.0/gems/twitter-6.1.0/lib/twitter/streaming/response.rb:24:in on_headers_complete': Twitter::Error::Unauthorized from /home/menog/.gem/ruby/2.4.0/gems/twitter-6.1.0/lib/twitter/streaming/response.rb:19:in <<'
from /home/menog/.gem/ruby/2.4.0/gems/twitter-6.1.0/lib/twitter/streaming/response.rb:19:in <<' from /home/menog/.gem/ruby/2.4.0/gems/twitter-6.1.0/lib/twitter/streaming/connection.rb:22:in stream'
from /home/menog/.gem/ruby/2.4.0/gems/twitter-6.1.0/lib/twitter/streaming/client.rb:119:in request' from /home/menog/.gem/ruby/2.4.0/gems/twitter-6.1.0/lib/twitter/streaming/client.rb:37:in filter'
from other_retweet_bot.rb:26:in `

'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment