English | Japanese






一般設定

Twitter4J はいくつもの設定可能なプロパティが存在します。プロパティは twitter4j.properties ファイルから、ConfigurationBuilderクラスから、またはシステムプロパティから設定できます。

  1. twitter4j.properties から

  2. 標準的なプロパティファイルを "twitter4j.properties" という名前で保存します。 "twitter4j.properties" はカレントディレクトリ、またはクラスパスのルート(WEB-INF/classes等)に配置してください。

    debug=true
    oauth.consumerKey=*********************
    oauth.consumerSecret=******************************************
    oauth.accessToken=**************************************************
    oauth.accessTokenSecret=******************************************

  3. ConfigurationBuilder から

  4. ConfigurationBuilder クラスを使うと以下のようにプログラムから設定をすることができます。

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true)
      .setOAuthConsumerKey("*********************")
      .setOAuthConsumerSecret("******************************************")
      .setOAuthAccessToken("**************************************************")
      .setOAuthAccessTokenSecret("******************************************");
    TwitterFactory tf = new TwitterFactory(cb.build());
    Twitter twitter = tf.getInstance();

  5. システムプロパティ から

  6. システムプロパティから設定をすることもできます。システムプロパティから設定する場合はプロパティ名の先頭に "twitter4j." をつける必要があることに注意してください。

    $ java -Dtwitter4j.debug=true
        -Dtwitter4j.oauth.consumerKey=*********************
        -Dtwitter4j.oauth.consumerSecret=******************************************
        -Dtwitter4j.oauth.accessToken=**************************************************
        -Dtwitter4j.oauth.accessTokenSecret=******************************************
        -cp twitter4j-core-2.2.5.jar:yourApp.jar yourpackage.Main

プロパティ一覧

一般

プロパティ名説明デフォルト値
debugデバッグ有効化フラグ。内蔵 Logger 使用時のみ有効。false
includeRTsタイムイン取得メソッドの返り値にRwteetsを含めるかどうかのフラグ。true
includeEntitiesタイムイン取得メソッドの返り値に追加情報を含めるかどうかのフラグ。true
jsonStoreEnabledDataObjectFactoryにJSONデータを保存するかどうかのフラグ。false
mbeanEnabledMBeanを有効化するかどうかのフラグ。false

OAuth

プロパティ名説明デフォルト値
oauth.consumerKeyデフォルト OAuth consumer keynull
oauth.consumerSecretデフォルト OAuth consumer secretnull
oauth.accessTokenデフォルト OAuth access tokennull
oauth.accessTokenSecretデフォルト OAuth access token secretnull

Basic / xAuth 認証

プロパティ名説明デフォルト値
userデフォルトのスクリーン名null
passwordデフォルトのパスワードnull

ストリーミング

プロパティ名説明デフォルト値
stream.user.repliesAllreplies=all を有効化するtrue

HTTP接続

プロパティ名説明デフォルト値
http.connectionTimeoutHTTP接続タイムアウト(ミリ秒)20000
http.readTimeoutHTTPリードタイムアウト(ミリ秒)120000
http.streamingReadTimeoutストリーミングAPI の HTTPリードタイムアウト(ms)300000
http.retryCountHTTPリトライ回数0
http.retryIntervalSecsHTTPリトライ間隔(秒)5
http.useSSLSSL接続有効化フラグfalse
http.prettyDebugデバッグ出力を整形するかどうかfalse

HTTPプロキサーバ

プロパティ名説明デフォルト値
http.proxyHostHTTPプロキシサーバホスト名null
http.proxyPortHTTPプロキシサーバポート番号null
http.proxyUserHTTPプロキシサーバユーザ名null
http.proxyPasswordHTTPプロキシサーバパスワードnull

メディアサポート

プロパティ名説明デフォルト値
media.providerデフォルトメディアプロバイダ
サポートされるプロバイダ:
imgly, plixi, lockerz, twipple, twitgoo, twitpic, yfrog
yrfog
media.providerAPIKeyメディアプロバイダAPI Keynull

ベースURL

プロパティ名説明デフォルト値
restBaseURLREST API ベース URLhttp://api.twitter.com/1/
searchBaseURLSearch API ベース URLhttp://search.twitter.com/
streamBaseURLStreaming API ベース URLhttp://stream.twitter.com/1/
siteStreamBaseURLSite Streams API ベース URLhttp://sitestream.twitter.com/2b/
userStreamBaseURLUser Stream API ベース URLhttps://userstream.twitter.com/2/
oauth.requestTokenURLOAuth request token URLhttp://api.twitter.com/oauth/request_token
oauth.accessTokenURLOAuth access token URLhttp://api.twitter.com/oauth/access_token
oauth.authorizationURLOAuth authorization URLhttp://api.twitter.com/oauth/authorize
oauth.authenticationURLOAuth authentication URLhttp://api.twitter.com/oauth/authenticate

非同期

プロパティ名説明デフォルト値
async.numThreads非同期処理スレッド数1
async.dispatcherImpl非同期処理実装クラス名twitter4j.internal.async.DispatcherImpl

ログ設定

デフォルト Twitter4J は標準出力にログを記録します。SLF4J, Commons-Logging, Log4J のいずれかがクラスパスに存在する場合はそのログライブラリを使ってメッセージが出力されます。-Dtwitter4j.loggerFactory=twitter4j.internal.logging.NullLoggerFactory をシステムプロパティに指定することでログ出力を止めることも出来ます。