忍者ブログ
  • 2024.04
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 2024.06
[PR]
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

【2024/05/03 20:41 】 |
twitterAPIを使うには(途中)
twitter公式のAPIドキュメントページは以下。
http://apiwiki.twitter.com/w/page/22554679/Twitter-API-Documentation
http://dev.twitter.com/doc

日本語で参考になるWikiのページ
http://usy.jp/twitter/index.php?Twitter%20API#y369b038



主に、
public_timeline 全twitterの最新20件
home_timeline あるユーザのつぶやきと、フォローイングしてる人のつぶやき20件
friends_timeline あるユーザの友人(フォローイング)リスト
user_timeline あるユーザの最新つぶやき20件
がある。

Javaの場合、
例えば、public_timelineを使いたいときは、

String requestUrl = "http://api.twitter.com/1/statuses/public_timeline.xml";
URL accessURL = new URL(requestUrl);
URLConnection con = accessURL.openConnection();

とリクエスト送信すれば、全つぶやき(全世界のtwitter登録者のツイート)の最新20件がxml形式で取得できる。
(xmlの他、json,atom,rss形式が可能)

user_timelineを使いたいときは、ユーザの名前をmynameとすると、

String requestUrl = "http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=myname";
URL accessURL = new URL(requestUrl);
URLConnection con = accessURL.openConnection();

とするとxmlで取得できる。

ここまでは非常に簡単。
認証が不要。


次に、home_timelineが欲しい場合。
これはOAuth認証が必要になる。

説明(公式英語)
http://dev.twitter.com/pages/auth

このページで、自分がtwitterAPIを使うアプリケーションを登録する。
http://twitter.com/apps/new

JavaでOAuth認証してtwitterAPIを使う参考ページ
http://blog.unfindable.net/archives/788


OAuthのライブラリ(.jar)をダウンロードして追加する。
OAuthCommunicationExceptionが発生して巧く行かず。

PR
【2011/05/15 18:47 】 | Web系 | 有り難いご意見(0) | トラックバック()
<<swingでお絵描きソフトを作る | ホーム | JavaでHTTPリクエストの方法>>
有り難いご意見
貴重なご意見の投稿














虎カムバック
トラックバックURL

<<前ページ | ホーム | 次ページ>>