English | Japanese | Korean

 



Generic properties

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 : -

  1. via twitter4j.properties

  2. 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=******************************************

  3. via ConfigurationBuilder

  4. You can use ConfigurationBuilder class to configure Twitter4J programatically as follows:

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

  5. via System Properties

  6. 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.1.jar:yourApp.jar yourpackage.Main

  7. via environment variables

  8. You can configure Twitter4J via environment variables as well. Note that you need "twitter4j." prefix. This makes it easier to test, stage and deploy apps running on Heroku.

    $ 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.0.1.jar:yourApp.jar yourpackage.Main
    On Heroku:
    $ heroku config:add oauth.consumerKey=**********
    $ heroku config:add oauth.consumerSecret=************
    $ heroku config:add oauth.accessToken=**************************************************
    $ heroku config:add oauth.accessTokenSecret=******************************************
    $ git push heroku master

Available Configuration Properties

Misc.

Property nameDescriptionDefault value
debugEnables deubg output. Effective only with the embedded logger.false
includeRTsIf set to true, retweets will be included in the timeline methods' resopnse.true
includeEntitiesIf set to true, entities will be included in the timeline methods' resopnse.true
includeMyRetweetset to true, any statuses returned that have been retweeted by the authenticating user will include an additional field: Status#getCurrentUserRetweetId ()true
jsonStoreEnabledIf set to true, raw JSON forms will be stored in DataObjectFactory.false
mbeanEnabledIf set to true, mbean will be registerd.false
loggerFactoryLogger implimentation
Supported implimentations:
 twitter4j.internal.logging.SLF4JLoggerFactory
 twitter4j.internal.logging.CommonsLoggingLoggerFactory
 twitter4j.internal.logging.Log4JLoggerFactory
 twitter4j.internal.logging.JULLoggerFactory
 twitter4j.internal.logging.NullLoggerFactory
 twitter4j.internal.logging.StdNullLoggerFactory
null
contributingTosets the user id contributing to.-1L

OAuth

Property nameDescriptionDefault value
oauth.consumerKeyDefault OAuth consumer keynull
oauth.consumerSecretDefault OAuth consumer secretnull
oauth.accessTokenDefault OAuth access tokennull
oauth.accessTokenSecretDefault OAuth access token secretnull

Basic / xAuth authentication

Property nameDescriptionDefault value
userDefault screen namenull
passwordDefault passwordnull

Streaming

Property nameDescriptionDefault value
stream.user.repliesAllenables replies=all parameterfalse
stream.enableStallWarningsset to true to receive stall warningstrue

HTTP connection

Property nameDescriptionDefault value
http.connectionTimeoutHttp connection timeout in milliseconds20000
http.readTimeoutHttp read timeout in milliseconds120000
http.streamingReadTimeoutStreaming API's Http Read timeout in milliseconds300000
http.retryCountNumber of HTTP retries0
http.retryIntervalSecsHTTP retry interval in seconds5
http.prettyDebugprettify JSON debug output if set to true.false

HTTP proxy server

Property nameDescriptionDefault value
http.proxyHostHTTP proxy server host namenull
http.proxyPortHTTP proxy server portnull
http.proxyUserHTTP proxy server user namenull
http.proxyPasswordHTTP proxy server passwordnull

Media support

Property nameDescriptionDefault value
media.providerdefault media provider
Supported providers:
twitter, imgly, plixi, lockerz, twipple, twitgoo, twitpic, yfrog
twitter
media.providerAPIKey media provider API Keynull

Base URLs

Property nameDescriptionDefault value
restBaseURLREST API base URLhttps://api.twitter.com/1.1/
streamBaseURLStreaming API base URLhttps://stream.twitter.com/1.1/
siteStreamBaseURLSite Streams API base URLhttps://sitestream.twitter.com/1.1/
userStreamBaseURLUser Stream API base URLhttps://userstream.twitter.com/1.1/
oauth.requestTokenURLOAuth request token URLhttps://api.twitter.com/oauth/request_token
oauth.accessTokenURLOAuth access token URLhttps://api.twitter.com/oauth/access_token
oauth.authorizationURLOAuth authorization URLhttps://api.twitter.com/oauth/authorize
oauth.authenticationURLOAuth authentication URLhttps://api.twitter.com/oauth/authenticate

Asynchronous

Property nameDescriptionDefault value
async.numThreadsNumber of threads handling asynchronous invocations1
async.dispatcherImplAsynchronous dispatcher implementation class nametwitter4j.DispatcherImpl
async.daemonEnabledSpecifies if async threads shouldd be daemonstrue

Logger Configuration

By default, Twitter4J prints log messages to standard output. If any of SLF4J, Commons-Logging, Log4J is in the classpath, log messages will be printed via the available logging library. You can disable logging by specifying -Dtwitter4j.loggerFactory=twitter4j.internal.logging.NullLoggerFactory to the system properties.