Head to www.apps.twitter.com to create a new app to get your keys. Tip: If you want to set up a new account just for the bot, use a Google voice number to register for a new account
can use them in ruby projects also. Setting up our client to make requests to Twitter: require 'twitter' client = Twitter::REST::Client.new do |config| config.consumer_key = ENV[CONSUMER_KEY] config.consumer_secret = ENV[CONSUMER_KEY] config.access_token = ENV[ACCESS_TOKEN] config.access_token_secret = ENV[ACCESS_TOKEN_SECRET] end Config Keys for @hitchbot_ghost
can use them in ruby projects also. Setting up our client to make requests to Twitter: require 'twitter' client = Twitter::REST::Client.new do |config| config.consumer_key = ENV[CONSUMER_KEY] config.consumer_secret = ENV[CONSUMER_KEY] config.access_token = ENV[ACCESS_TOKEN] config.access_token_secret = ENV[ACCESS_TOKEN_SECRET] end
Tweet require 'twitter' client = Twitter::REST::Client.new do |config| config.consumer_key = ENV[CONSUMER_KEY] config.consumer_secret = ENV[CONSUMER_KEY] config.access_token = ENV[ACCESS_TOKEN] config.access_token_secret = ENV[ACCESS_TOKEN_SECRET] end #tweet with random number so you can find yours on the shared account #if using your own keys, you don’t have to worry about my_number my_number = rand(100) client.update("Test tweet #{my_number}") puts "Look for the tweet: Test tweet #{my_number}"
now communicate with Twitter’s API. Here’s some examples of what we can do: Send a tweet from your account: client.update("I'm tweeting from the @philyrb and @phillyjsdev meetup!") Follow a user:(you can use their handle or UserId) client.follow("gem") client.follow(213747670) Or...find the 3 most recent marriage proposals to Justin Beiber: client.search("to:justinbieber marry me", result_type: "recent").take(3).each do |tweet| puts tweet.text end
a given radius containing “#ruby” or “#javascript” and favorites the tweet. First, let’s find 50 tweets containing “#ruby” or “#javascript” and print out the results to our console client.search("#ruby").take(50).each do |tweet| puts "#{tweet.user.screen_name}: #{tweet.text}" puts "----------------------------------------" end client.search("#javascript").take(50).each do |tweet| puts "#{tweet.user.screen_name}: #{tweet.text}" puts "----------------------------------------" end
bit. We’re already getting tweets to display in the console. Let’s narrow our search to people within 25 miles We need to pass Twitter the Latitude and Longitude as part of our options. For now, just go to Google Maps right- click for lat and long coords. (extra credit: look into geocoder gem) The basic format for the #search method is client.search("query", { options }) Let’s add some options to our search. Some of the available options are: • geocode (search by latitude and longitude) • language • result_type (most recent, popular, etc.) client.search("#ruby").take(50).each do |tweet| puts "#{tweet.user.screen_name}: #{tweet.text}" puts "----------------------------------------" end Add geocode to our search: client.search("#ruby", {result_type: "recent", geocode: "39.9525839, -75.1652215,10mi"}).take(50).each do |tweet| puts "#{tweet.user.screen_name}: #{tweet.text}" end