
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 : -
via twitter4j.properties
via ConfigurationBuilder
via System 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=******************************************
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();
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-2.2.5.jar:yourApp.jar yourpackage.Main
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 |
| jsonStoreEnabled | If set to true, raw JSON forms will be stored in DataObjectFactory. | false |
| mbeanEnabled | If set to true, mbean will be registerd. | false |
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 |
Basic / xAuth authentication
| Property name | Description | Default value |
|---|---|---|
| user | Default screen name | null |
| password | Default password | null |
Streaming
| Property name | Description | Default value |
|---|---|---|
| stream.user.repliesAll | enables replies=all parameter | 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.useSSL | Enables SSL connection. | false |
| 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 |
Media support
| Property name | Description | Default value |
|---|---|---|
| media.provider | default media provider Supported providers: imgly, plixi, lockerz, twipple, twitgoo, twitpic, yfrog | yrfog |
| media.providerAPIKey | media provider API Key | null |
Base URLs
| Property name | Description | Default value |
|---|---|---|
| restBaseURL | REST API base URL | http://api.twitter.com/1/ |
| searchBaseURL | Search API base URL | http://search.twitter.com/ |
| streamBaseURL | Streaming API base URL | http://stream.twitter.com/1/ |
| siteStreamBaseURL | Site Streams API base URL | http://sitestream.twitter.com/2b/ |
| userStreamBaseURL | User Stream API base URL | https://userstream.twitter.com/2/ |
| oauth.requestTokenURL | OAuth request token URL | http://api.twitter.com/oauth/request_token |
| oauth.accessTokenURL | OAuth access token URL | http://api.twitter.com/oauth/access_token |
| oauth.authorizationURL | OAuth authorization URL | http://api.twitter.com/oauth/authorize |
| oauth.authenticationURL | OAuth authentication URL | http://api.twitter.com/oauth/authenticate |
Asynchronous
| Property name | Description | Default value |
|---|---|---|
| async.numThreads | Number of threads handling asynchronous invocations | 1 |
| async.dispatcherImpl | Asynchronous dispatcher implementation class name | twitter4j.internal.async.DispatcherImpl |
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.