Twitter APIを使ってみる

この情報は古いのでmemoに移動しました。

ふと気がつきました。TimelogともごもごのAPIを使ったのに、Twitter APIを使っていないことに・・・順番逆やんorz..
APIドキュメントは以下にありました
http://groups.google.com/group/twitter-development-talk/web/api-documentation
状態取得には以下のようなものがあります。

1) public_timeline
パブリックな状態を20個とる
http://twitter.com/statuses/public_timeline.{format}
format=>xml, json, rss, atom
2) friends_timeline
友達の状態を最大20個とる
http://twitter.com/statuses/friends_timeline.{format}
特定の友達のをとる場合は以下のようにも書ける
http://twitter.com/statuses/friends_timeline/{id}.{format}
sinceパラメータを使うと指定の時間からの状態をとれる
format=>xml, json, rss, atom
3) user_timeline
ユーザの状態を最大20個とる
http://twitter.com/statuses/user_timeline.{format}
特定のユーザのをとる場合は以下のようにも書ける
http://twitter.com/statuses/user_timeline/{id}.{format}
countパラメータで取得する数を指定できるがシステム負荷削減のため20以上の指定はできない
sinceパラメータを使うと指定の時間からの状態をとれる
format=>xml, json, rss, atom
4) show
状態いっことる
http://twitter.com/statuses/show/{id}.{format}
format=>xml, json
5) update
状態を更新する
http://twitter.com/statuses/update.{format}
format=>xml, json
6) replies
リプライを20個とる
format=>xml, json, rss, atom
7) destroy
状態を消す
http://twitter.com/statuses/destroy/{id}.format
id=>状態ID
このほか、ユーザ情報(friends,followersなど)を取得するもの、DirectMessageの操作、友達リストの操作などほぼすべての機能がAPIとして公開されています。

Twitterもサンプルを作ろうかと思った瞬間、Twitterくらいになるとライブラリがあるだろうと思い探したところ以下を発見。API数も多いので今回は下記ライブラリを使うことにします。

http://labs.transrain.net/products/services_twitter/
ライブラリのおかげで簡単にサンプルができました。このライブラリ取得形式はjsonになっているのでそのままjavascriptで記述してもよかったのですが、Timelogやもごもごのサンプルを流用したかったのでjsonをオブジェクトに変換してphpでhtmlを出力しました。

サンプルはこれです。

http://labs.makotokw.com/s/sandbox/twitter