A Thanks for following me twitter bot using ruby
you guys must have noticed that anyone follows my twitter account http://www.twitter.com/blaz_boy gets a DM that says thanks for following me, and this DM is coming almost instantaneously, this is the script is wrote to add this feature to my twitter account,
if you have any comments please let me know.
#!/usr/bin/env ruby
require 'Twitter'
# 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: ''}
me = 'Blaze Boy' # to prevent DM yourself
Thread.new do
loop do
begin
rClient = Twitter::REST::Client.new config
sClient = Twitter::Streaming::Client.new(config)
sClient.user do |object|
if object.is_a? Twitter::Streaming::Event and object.name==:follow
user = object.source
if user.name != me
rClient.create_direct_message user, "Thanks for following me #{user.name} :)"
puts "New follower : #{object.source.name}"
end
end
end
rescue
puts 'error occurred, sleeping for 5 seconds'
sleep 5
end
end
end
loop { sleep 5 }
Written by Emad Elsaid
Related protips
2 Responses
You are the best :D
I am beginner at this and my project is to make a twitter bot. So, I was wondering what is a most basic code for tweeting "hello world"?
Thanks and your answer will be appreciated.
over 1 year ago
·
the twitter gem readme has a good examples of usage
https://github.com/sferik/twitter
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#