TwitterのAPIについてのメモ
なんか作ってみたいと思ってるので、そのメモ。
大きく分けて2つのAPIがあるみたい。
Streaming API
こっちを使うつもりはないのであんまり見てませんが。
The Twitter Streaming API allows high-throughput near-realtime access to various subsets of public and protected Twitter data.
Developers are strongly encouraged to read all of the documentation linked to by this document thoroughly.
Twitterのリアルタイムな情報を利用できます、ってなこっちゃ。
タイムラインをリアルタイムに取得して反映・・みたいな仕様にする場合は、こっちがよさげ。
HTTP Basic Authentication or OAuth is required to access the streaming API methods.
A client must, for Basic Authentication, provide the credentials of a valid Twitter account, or for OAuth, sign the request appropriately.
ただ使うには認証が必要です。
REST API
RESTについては最近知ったとこなので、いまいちな解釈かもしれませんがー。
いわゆるHttpでリクエストして結果をもらう、とか「いわゆるWebのAPI」っていうのは大抵コレなんやろうか。
取得できる内容は、以下の分類。
- Timelines
- Tweets
- Search
- Direct Messages
- Friends & Followers
- Users
- Suggested Users
- Favorites
- Lists
- Accounts
- Notification
- Saved Searches
- Local Trends
- Places & Geo
- Trends
- Block
- Spam Reporting
- OAuth
- Help
- Legal
- Deprecated
多いわ!w
なにはともあれ、Twitterの全てがココに!
それぞれGETかPOSTかどっちもか、できます。
はてさて。
REST -Search API
今回狙ってるのはこいつ!
参考:GET search | Twitter Developers
参考:Using the Twitter Search API | Twitter Developers
参考:Tweet Entities | Twitter Developers
だいたいこの3ページに知りたいことは全て書いてあるはず。
取得結果
JSONかatomかJSONPの形式から。
クエリ
1つ目と2つ目の参考URL参照。
include_entitiesをtrueにすると、参考URL3つ目にあるように、Tweet Entitiesなるものも取得可能。
Tweet text can potentially mention other users or lists, but also contain URLs, media, hashtags...
Instead of parsing the text yourself to try to extract those entities, you can use the entities attribute that contains this parsed and structured data.
メタデータってやつですね。
つぶやきの補足データ:リンクを含んでるか、ハッシュタグがあるか、などなど。
これは使えそうー!
利用制限
result_type
mixed / Popular / Recent
これがいまいちよくわかんない。
つぶやきには人気のもの、最近のものっていう独自の分類があって、そういったバイアスを含んだ結果を返すかどうか、ってことなんかな?
以上、メモでした。