harry’s memorandum

おれおれメモ

rubyでtwitterってできるのかな

簡単にできるみたいですね。でも便利だけどtwitterをいまいち楽しめないオールドタイプの自分が悲しい。。

まずはgemでインストール。依存関係のgemがすげー。

$ sudo gem install twitter
When you HTTParty, you must party hard!
Successfully installed rubyforge-1.0.5
Successfully installed hoe-2.3.3
Successfully installed ruby-hmac-0.3.2
Successfully installed oauth-0.3.6
Successfully installed mash-0.0.3
Successfully installed crack-0.1.4
Successfully installed httparty-0.4.3
Successfully installed twitter-0.6.15

botは簡単に作れそうだ。*1

require 'rubygems'
require 'twitter'

httpauth = Twitter::HTTPAuth.new('myaccount@twitter.example.com', 'mypassword')
twitter = Twitter::Base.new(httpauth)

twitter.update('foo... foo..')

HTTPAuthっていうのを使ったけど、サイトをみるとセキュリティ上の問題でOAuthというのを使うのがいいみたいですね。
http://apiwiki.twitter.com/Authentication

参考

exapmlesのソースがわかりやすい。

*1:ためにしポストしてみたら「APIで..」と表示されてた。