Created
September 2, 2010 14:32
-
-
Save ruanwz/562366 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'twitter' | |
config = File.exists?("#{ENV['HOME']}/.twitter") ? YAML::load(open("#{ENV['HOME']}/.twitter")) : Hash.new | |
if config.empty? | |
print "> what was the comsumer token twitter provided you with? " | |
config['token'] = gets.chomp | |
print "> what was the comsumer secret twitter provided you with? " | |
config['secret'] = gets.chomp | |
File.open( "#{ENV['HOME']}/.twitter", 'w' ) do |out| | |
YAML.dump( config, out ) | |
end | |
end | |
oauth = Twitter::OAuth.new(config['token'], config['secret']) | |
if config['atoken'] and config['asecret'] | |
oauth.authorize_from_access(config['atoken'], config['asecret']) | |
else | |
puts rtoken = oauth.request_token.token | |
puts rsecret = oauth.request_token.secret | |
puts rurl = oauth.request_token.authorize_url | |
puts "access the url above" | |
print "> what was the PIN twitter provided you with? " | |
pin = gets.chomp | |
oauth.authorize_from_request(rtoken, rsecret, pin) | |
config['atoken'] = oauth.access_token.token | |
config['asecret'] = oauth.access_token.secret | |
File.open( "#{ENV['HOME']}/.twitter", 'w' ) do |out| | |
YAML.dump( config, out ) | |
end | |
end | |
client = Twitter::Base.new(oauth) | |
client.friends_timeline.each { |tweet| puts tweet.inspect } | |
client.user_timeline.each { |tweet| puts tweet.inspect } | |
client.mentions.each { |tweet| puts tweet.inspect } | |
client.update("Heeeyyyyoooo from Twitter Gem at #{Time.now}!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment