Configuration

There are a number of properties available for configuring Twitter4J. You can specify properties via twitter4j.properties file, ConfigurationBuilder class or System Property as follows : –

By twitter4j.properties

Save a standard properties file named “twitter4j.properties”. Place it to either the current directory, root of the classpath directory.

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

By builder

You can use Builder class to configure Twitter4J programatically as follows:

Twitter twitter = Twitter.newBuilder();
  .debugEnabled(true)
  .oAuthConsumer("*********************", "******************************************")
  .oAuthAccessToken("**************************************************", "******************************************")
  .build();

By System Properties

You can configure Twitter4J via System properties as well. Note that you need “twitter4j.” prefix.

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

By Environment Variables

You can configure Twitter4J via environment variables as well. Note that you need “twitter4j_” prefix.

$ export twitter4j_debug=true
$ export twitter4j_oauth_consumerKey=*********************
$ export twitter4j_oauth_consumerSecret=******************************************
$ export twitter4j_oauth_accessToken=**************************************************
$ export twitter4j_oauth_accessTokenSecret=******************************************
$ java -cp twitter4j-core-4.1.1.jar:yourApp.jar yourpackage.Main

On Heroku:

$ heroku config:add twitter4j_oauth_consumerKey=**********
$ heroku config:add twitter4j_oauth_consumerSecret=************
$ heroku config:add twitter4j_oauth_accessToken=**************************************************
$ heroku config:add twitter4j_oauth_accessTokenSecret=******************************************
$ git push heroku master

Available Configuration Properties

Misc.

Property name Description Default value
debug Enables deubg output. Effective only with the embedded logger. false
includeRTs If set to true, retweets will be included in the timeline methods’ resopnse. true
includeEntities If set to true, entities will be included in the timeline methods’ resopnse. true
includeMyRetweet set to true, any statuses returned that have been retweeted by the authenticating user will include an additional field: Status#getCurrentUserRetweetId () true
jsonStoreEnabled If set to true, raw JSON forms will be stored in DataObjectFactory. false
mbeanEnabled If set to true, mbean will be registerd. false
contributingTo sets the user id contributing to. -1L

OAuth

Property name Description Default value
oauth.consumerKey Default OAuth consumer key null
oauth.consumerSecret Default OAuth consumer secret null
oauth.accessToken Default OAuth access token null
oauth.accessTokenSecret Default OAuth access token secret null

Streaming

Property name Description Default value
stream.user.repliesAll enables replies=all parameter false
stream.enableStallWarnings set to true to receive stall warnings true

HTTP connection

Property name Description Default value
http.connectionTimeout Http connection timeout in milliseconds 20000
http.readTimeout Http read timeout in milliseconds 120000
http.streamingReadTimeout Streaming API’s Http Read timeout in milliseconds 300000
http.retryCount Number of HTTP retries 0
http.retryIntervalSecs HTTP retry interval in seconds 5
http.prettyDebug prettify JSON debug output if set to true. false

 

HTTP proxy server

 

Property name Description Default value
http.proxyHost HTTP proxy server host name null
http.proxyPort HTTP proxy server port null
http.proxyUser HTTP proxy server user name null
http.proxyPassword HTTP proxy server password null

Recent Posts

  1. Twitter4J 4.1.2 released Leave a reply
  2. Twitter4J 4.1.1 released Leave a reply
  3. Twitter4J 4.1.0 released Leave a reply
  4. Twitter4J 4.0.7 リリース Leave a reply
  5. General availability of Twitter4J 4.0.7 Leave a reply
  6. #Twitter4J 4.0.7-SNAPSHOT リリース – DMを利用するアプリは要移行 Leave a reply
  7. releasing #Twitter4J 4.0.7-SNAPSHOT – Apps using DM need to migrate Leave a reply
  8. #Twitter4J 4.0.4 リリース – 長文DMサポート、Lambda表記サポートなど Leave a reply
  9. #Twitter4J 4.0.4 released – supports longer DM texts, lambda expression and more Leave a reply