CONTACT
お問い合わせ

twitter4jを利用したTwitterクライアント実装

twitter4jを利用したTwitterクライアントの実装方法を説明する。

目次

実装手順

  1. 前提
  2. 動作イメージ
  3. Twitter Appsでアプリ登録
  4. ソースコード

1.前提

Twitterアカウントを作成している事。

2.動作イメージ

準備中

3.Twitter Appsでアプリ登録

Twitter Appsにアクセス
「https://apps.twitter.com/」にアクセスする。
  ◎ Twitter Apps

アプリケーションの情報を登録

名称、説明、Webサイトなどを登録する。

アプリケーションが作成されるとカスタマーキーなどが生成される

権限設定

Read/Write権限を付与する。

アクセストークン作成

アクセストークンを作成する。

アクセストークン作成完了

twitter4jからライブラリをダウンロードする

下記URLからライブラリをダウンロードする。
  ◎ Twitter4J公式
  ◎ ライブラリ

Jarファイルをクラスパスに含める

Jarファイルをクラスパスに含めておく。 ※Eclipseのビルドパスに設定

C:\>tree /f C:\Users\t_yamazoe\Desktop\twitter4j-4.0.4\lib
C:\USERS\T_YAMAZOE\DESKTOP\TWITTER4J-4.0.4\LIB
readme-libs.txt
twitter4j-async-4.0.4.jar
twitter4j-core-4.0.4.jar
twitter4j-examples-4.0.4.jar
twitter4j-media-support-4.0.4.jar
twitter4j-stream-4.0.4.jar

Javaアプリケーションの作成

twitter4j.propertiesを作成

※クラスパスが設定されている場所に作成
※「Twitter Appsでアプリ登録」で作成・登録したカスタマーキー、アクセストークンを設定する

Javaアプリケーションの実行

<標準出力>

[Start]
[Sun Nov 19 02:58:12 JST 2017]serialVersionUID: ******
[Sun Nov 19 02:58:12 JST 2017]debug: true
[Sun Nov 19 02:58:12 JST 2017]user: null
[Sun Nov 19 02:58:12 JST 2017]password: null
[Sun Nov 19 02:58:12 JST 2017]httpConf: MyHttpClientConfiguration{httpProxyHost='null', httpProxyUser='null', httpProxyPassword='null', httpProxyPort=-1, httpConnectionTimeout=20000, httpReadTimeout=120000, prettyDebug=false, gzipEnabled=true}
[Sun Nov 19 02:58:12 JST 2017]httpStreamingReadTimeout: 40000
[Sun Nov 19 02:58:12 JST 2017]httpRetryCount: 0
[Sun Nov 19 02:58:12 JST 2017]httpRetryIntervalSeconds: 5
[Sun Nov 19 02:58:12 JST 2017]oAuthConsumerKey: ******
[Sun Nov 19 02:58:12 JST 2017]oAuthConsumerSecret:******
[Sun Nov 19 02:58:12 JST 2017]oAuthAccessToken: ******
[Sun Nov 19 02:58:12 JST 2017]oAuthAccessTokenSecret:******
[Sun Nov 19 02:58:12 JST 2017]oAuth2TokenType: null
[Sun Nov 19 02:58:12 JST 2017]oAuth2AccessToken: null
[Sun Nov 19 02:58:12 JST 2017]oAuth2Scope: null
[Sun Nov 19 02:58:12 JST 2017]oAuthRequestTokenURL: https://api.twitter.com/oauth/request_token
[Sun Nov 19 02:58:12 JST 2017]oAuthAuthorizationURL: https://api.twitter.com/oauth/authorize
[Sun Nov 19 02:58:12 JST 2017]oAuthAccessTokenURL: https://api.twitter.com/oauth/access_token
[Sun Nov 19 02:58:12 JST 2017]oAuthAuthenticationURL: https://api.twitter.com/oauth/authenticate
[Sun Nov 19 02:58:12 JST 2017]oAuth2TokenURL: https://api.twitter.com/oauth2/token
[Sun Nov 19 02:58:12 JST 2017]oAuth2InvalidateTokenURL: https://api.twitter.com/oauth2/invalidate_token
[Sun Nov 19 02:58:12 JST 2017]restBaseURL: https://api.twitter.com/1.1/
[Sun Nov 19 02:58:12 JST 2017]streamBaseURL: https://stream.twitter.com/1.1/
[Sun Nov 19 02:58:12 JST 2017]userStreamBaseURL: https://userstream.twitter.com/1.1/
[Sun Nov 19 02:58:12 JST 2017]siteStreamBaseURL: https://sitestream.twitter.com/1.1/
[Sun Nov 19 02:58:12 JST 2017]uploadBaseURL: https://upload.twitter.com/1.1/
[Sun Nov 19 02:58:12 JST 2017]dispatcherImpl: twitter4j.DispatcherImpl
[Sun Nov 19 02:58:12 JST 2017]asyncNumThreads: 1
[Sun Nov 19 02:58:12 JST 2017]loggerFactory: null
[Sun Nov 19 02:58:12 JST 2017]contributingTo: -1
[Sun Nov 19 02:58:12 JST 2017]includeMyRetweetEnabled: true
[Sun Nov 19 02:58:12 JST 2017]includeEntitiesEnabled: true
[Sun Nov 19 02:58:12 JST 2017]trimUserEnabled: false
[Sun Nov 19 02:58:12 JST 2017]jsonStoreEnabled: false
[Sun Nov 19 02:58:12 JST 2017]mbeanEnabled: false
[Sun Nov 19 02:58:12 JST 2017]userStreamRepliesAllEnabled: false
[Sun Nov 19 02:58:12 JST 2017]userStreamWithFollowingsEnabled: true
[Sun Nov 19 02:58:12 JST 2017]stallWarningsEnabled: true
[Sun Nov 19 02:58:12 JST 2017]applicationOnlyAuthEnabled: false
[Sun Nov 19 02:58:12 JST 2017]mediaProvider: TWITTER
[Sun Nov 19 02:58:12 JST 2017]mediaProviderAPIKey: null
[Sun Nov 19 02:58:12 JST 2017]mediaProviderParameters: null
[Sun Nov 19 02:58:12 JST 2017]daemonEnabled: true
[Sun Nov 19 02:58:12 JST 2017]instances: [ConfigurationBase{debug=true, user='null', password='null', httpConf=MyHttpClientConfiguration{httpProxyHost='null', httpProxyUser='null', httpProxyPassword='null', httpProxyPort=-1, httpConnectionTimeout=20000, httpReadTimeout=120000, prettyDebug=false, gzipEnabled=true}, httpStreamingReadTimeout=40000, httpRetryCount=0, httpRetryIntervalSeconds=5, oAuthConsumerKey='******', oAuthConsumerSecret='******', oAuthAccessToken='******', oAuthAccessTokenSecret='******', oAuth2TokenType='null', oAuth2AccessToken='null', oAuth2Scope='null', oAuthRequestTokenURL='https://api.twitter.com/oauth/request_token', oAuthAuthorizationURL='https://api.twitter.com/oauth/authorize', oAuthAccessTokenURL='https://api.twitter.com/oauth/access_token', oAuthAuthenticationURL='https://api.twitter.com/oauth/authenticate', oAuth2TokenURL='https://api.twitter.com/oauth2/token', oAuth2InvalidateTokenURL='https://api.twitter.com/oauth2/invalidate_token', restBaseURL='https://api.twitter.com/1.1/', uploadBaseURL='https://upload.twitter.com/1.1/', streamBaseURL='https://stream.twitter.com/1.1/', userStreamBaseURL='https://userstream.twitter.com/1.1/', siteStreamBaseURL='https://sitestream.twitter.com/1.1/', dispatcherImpl='twitter4j.DispatcherImpl', asyncNumThreads=1, loggerFactory='null', contributingTo=-1, includeMyRetweetEnabled=true, includeEntitiesEnabled=true, trimUserEnabled=false, jsonStoreEnabled=false, mbeanEnabled=false, userStreamRepliesAllEnabled=false, userStreamWithFollowingsEnabled=true, stallWarningsEnabled=true, applicationOnlyAuthEnabled=false, mediaProvider='TWITTER', mediaProviderAPIKey='null', mediaProviderParameters=null, daemonEnabled=true}]
[Sun Nov 19 02:58:13 JST 2017]Request:
[Sun Nov 19 02:58:13 JST 2017]GET https://api.twitter.com/1.1/account/verify_credentials.json
[Sun Nov 19 02:58:13 JST 2017]OAuth base string: GET&https%3A%2F%2Fapi.twitter.com%2F1.1%2Faccount%2
Fverify_credentials.json&oauth_consumer_key%******%26oauth_nonce%******%26oauth_signature_method%******%26
oauth_timestamp%3D1511027893%26oauth_token%******%26oauth_version%3D1.0
[Sun Nov 19 02:58:13 JST 2017]OAuth signature: ******
[Sun Nov 19 02:58:13 JST 2017]Authorization:******
[Sun Nov 19 02:58:13 JST 2017]X-Twitter-Client-URL: http://twitter4j.org/en/twitter4j-4.0.4.xml
[Sun Nov 19 02:58:13 JST 2017]X-Twitter-Client: Twitter4J
[Sun Nov 19 02:58:13 JST 2017]Accept-Encoding: gzip
[Sun Nov 19 02:58:13 JST 2017]User-Agent: twitter4j http://twitter4j.org/ /4.0.4
[Sun Nov 19 02:58:13 JST 2017]X-Twitter-Client-Version: 4.0.4
[Sun Nov 19 02:58:13 JST 2017]Response:
[Sun Nov 19 02:58:13 JST 2017]content-type: application/json;charset=utf-8
[Sun Nov 19 02:58:13 JST 2017]x-frame-options: SAMEORIGIN
[Sun Nov 19 02:58:13 JST 2017]HTTP/1.1 200 OK
[Sun Nov 19 02:58:13 JST 2017]x-response-time: 123
[Sun Nov 19 02:58:13 JST 2017]content-encoding: gzip
[Sun Nov 19 02:58:13 JST 2017]date: Sat, 18 Nov 2017 17:58:13 GMT
[Sun Nov 19 02:58:13 JST 2017]x-transaction: ******
[Sun Nov 19 02:58:13 JST 2017]cache-control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0
[Sun Nov 19 02:58:13 JST 2017]x-content-type-options: nosniff
[Sun Nov 19 02:58:13 JST 2017]expires: Tue, 31 Mar 1981 05:00:00 GMT
[Sun Nov 19 02:58:13 JST 2017]x-rate-limit-limit: 75
[Sun Nov 19 02:58:13 JST 2017]content-disposition: attachment; filename=json.json
[Sun Nov 19 02:58:13 JST 2017]x-twitter-response-tags: BouncerCompliant
[Sun Nov 19 02:58:13 JST 2017]x-twitter-response-tags: BouncerExempt
[Sun Nov 19 02:58:13 JST 2017]x-access-level: read-write
[Sun Nov 19 02:58:13 JST 2017]x-rate-limit-remaining: 74
[Sun Nov 19 02:58:13 JST 2017]last-modified: Sat, 18 Nov 2017 17:58:13 GMT
[Sun Nov 19 02:58:13 JST 2017]status: 200 OK
[Sun Nov 19 02:58:13 JST 2017]pragma: no-cache
[Sun Nov 19 02:58:13 JST 2017]x-connection-hash: ******
[Sun Nov 19 02:58:13 JST 2017]x-xss-protection: 1; mode=block
[Sun Nov 19 02:58:13 JST 2017]set-cookie: guest_id=******; Expires=Mon, 18 Nov 2019 17:58:13 UTC; Path=/; Domain=.twitter.com
[Sun Nov 19 02:58:13 JST 2017]set-cookie: lang=ja; Path=/
[Sun Nov 19 02:58:13 JST 2017]set-cookie: personalization_id="******"; Expires=Mon, 18 Nov 2019 17:58:13 UTC; Path=/; Domain=.twitter.com
[Sun Nov 19 02:58:13 JST 2017]content-length: 553
[Sun Nov 19 02:58:13 JST 2017]x-rate-limit-reset: 1511028793
[Sun Nov 19 02:58:13 JST 2017]server: tsa_m
[Sun Nov 19 02:58:13 JST 2017]strict-transport-security: max-age=631138519
[Sun Nov 19 02:58:13 JST 2017]{"location":"","default_profile":true,"profile_background_tile":false,"statuses_count":0,"lang":"ja",
"profile_link_color":"1DA1F2","id":******,"following":false,"protected":false,"favourites_count":0,"profile_text_color":"333333",
"description":"","verified":false,"contributors_enabled":false,"profile_sidebar_border_color":"C0DEED","name":"(株)エーフロンティア",
"profile_background_color":"F5F8FA","created_at":"Sat Nov 18 15:32:09 +0000 2017",
"is_translation_enabled":false,"default_profile_image":true,"followers_count":0,"has_extended_profile":false,
"profile_image_url_https":https://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png,"geo_enabled":false,
"geo_enabled":false,"profile_background_image_url":null,"profile_background_image_url_https":null,"follow_request_sent":false,
"entities":{"description":{"urls":[]}},"url":null,"utc_offset":null,"time_zone":null,"translator_type":"none",
"notifications":false,"profile_use_background_image":true,"friends_count":3,"profile_sidebar_fill_color":"DDEEF6",
"screen_name":"a_frontier_jp","id_str":"******",
"profile_image_url":"http://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png","listed_count":0,"is_translator":false}
名前   :(株)エーフロンティア
表示名 :a_frontier_jp
フォロー数 :3
フォロワー数:0
[Sun Nov 19 02:58:13 JST 2017]Request:
[Sun Nov 19 02:58:13 JST 2017]POST https://api.twitter.com/1.1/statuses/update.json
[Sun Nov 19 02:58:13 JST 2017]OAuth base string: POST&https%3A%2F%2Fapi.twitter.com%2F1.1%2Fstatuses%2
Fupdate.json&include_entities%3Dtrue%26oauth_consumer_key%******%26oauth_nonce%******%26oauth_signature_method%******%
26oauth_timestamp%3D1511027893%26oauth_token%******%26oauth_version%3D1.0%26status%3DTwitter4J%******
[Sun Nov 19 02:58:13 JST 2017]OAuth signature: ******
[Sun Nov 19 02:58:13 JST 2017]Authorization:******
[Sun Nov 19 02:58:13 JST 2017]X-Twitter-Client-URL: http://twitter4j.org/en/twitter4j-4.0.4.xml
[Sun Nov 19 02:58:13 JST 2017]X-Twitter-Client: Twitter4J
[Sun Nov 19 02:58:13 JST 2017]Accept-Encoding: gzip
[Sun Nov 19 02:58:13 JST 2017]User-Agent: twitter4j http://twitter4j.org/ /4.0.4
[Sun Nov 19 02:58:13 JST 2017]X-Twitter-Client-Version: 4.0.4
[Sun Nov 19 02:58:13 JST 2017]Post Params: status=******=true
[Sun Nov 19 02:58:13 JST 2017]Response:
[Sun Nov 19 02:58:13 JST 2017]HTTP/1.1 200 OK
[Sun Nov 19 02:58:13 JST 2017]content-type: application/json;charset=utf-8
[Sun Nov 19 02:58:13 JST 2017]x-frame-options: SAMEORIGIN
[Sun Nov 19 02:58:13 JST 2017]last-modified: Sat, 18 Nov 2017 17:58:13 GMT
[Sun Nov 19 02:58:13 JST 2017]status: 200 OK
[Sun Nov 19 02:58:13 JST 2017]x-response-time: 207
[Sun Nov 19 02:58:13 JST 2017]content-encoding: gzip
[Sun Nov 19 02:58:13 JST 2017]date: Sat, 18 Nov 2017 17:58:13 GMT
[Sun Nov 19 02:58:13 JST 2017]x-transaction: ******
[Sun Nov 19 02:58:13 JST 2017]pragma: no-cache
[Sun Nov 19 02:58:13 JST 2017]cache-control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0
[Sun Nov 19 02:58:13 JST 2017]x-connection-hash: ******
[Sun Nov 19 02:58:13 JST 2017]x-content-type-options: nosniff
[Sun Nov 19 02:58:13 JST 2017]x-xss-protection: 1; mode=block
[Sun Nov 19 02:58:13 JST 2017]expires: Tue, 31 Mar 1981 05:00:00 GMT
[Sun Nov 19 02:58:13 JST 2017]set-cookie: guest_id=******; Expires=Mon, 18 Nov 2019 17:58:13 UTC; Path=/; Domain=.twitter.com

[Sun Nov 19 02:58:13 JST 2017]set-cookie: lang=ja; Path=/
[Sun Nov 19 02:58:13 JST 2017]set-cookie: personalization_id="******"; Expires=Mon, 18 Nov 2019 17:58:13 UTC; Path=/; Domain=.twitter.com
[Sun Nov 19 02:58:13 JST 2017]content-length: 800
[Sun Nov 19 02:58:13 JST 2017]content-disposition: attachment; filename=json.json
[Sun Nov 19 02:58:13 JST 2017]server: tsa_m
[Sun Nov 19 02:58:13 JST 2017]strict-transport-security: max-age=631138519
[Sun Nov 19 02:58:13 JST 2017]x-tsa-request-body-time: 0
[Sun Nov 19 02:58:13 JST 2017]x-twitter-response-tags: BouncerCompliant
[Sun Nov 19 02:58:13 JST 2017]x-access-level: read-write
[Sun Nov 19 02:58:13 JST 2017]{"contributors":null,"text":"Twitter4Jテスト(^^)1","geo":null,"retweeted":false,"in_reply_to_screen_name":null,
"truncated":false,"lang":"ja","entities":{"symbols":[],"urls":[],"hashtags":[],"user_mentions":[]},"in_reply_to_status_id_str":null,
"is_quote_status":false,"id":******,"source":"<a href=\"http://www.a-fronter.jp\" rel=\"nofollow\">A-frontier-jp-TweetTest01<\/a>",
"in_reply_to_user_id_str":null,"favorited":false,"in_reply_to_status_id":null,"retweet_count":0,"created_at":"Sat Nov 18 17:58:13 +0000 2017",
"in_reply_to_user_id":null,"favorite_count":0,"id_str":"******","place":null,"user":{"location":"","default_profile":true,
"profile_background_tile":false,"statuses_count":1,"lang":"ja","profile_link_color":"1DA1F2","id":******,"following":false,"protected":false,
"favourites_count":0,"profile_text_color":"333333","description":"","verified":false,"contributors_enabled":false,
"profile_sidebar_border_color":"C0DEED","name":"(株)エーフロンティア","profile_background_color":"F5F8FA",
"created_at":"Sat Nov 18 15:32:09 +0000 2017","is_translation_enabled":false,"default_profile_image":true,"followers_count":0,
"has_extended_profile":false,"profile_image_url_https":https://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png,
"geo_enabled":false,"profile_background_image_url":null,"profile_background_image_url_https":null,"follow_request_sent":false,
"entities":{"description":{"urls":[]}},"url":null,"utc_offset":null,"time_zone":null,"translator_type":"none","notifications":false,
"profile_use_background_image":true,"friends_count":3,"profile_sidebar_fill_color":"DDEEF6","screen_name":"a_frontier_jp",
"id_str":"******","profile_image_url":http://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png,
"listed_count":0,"is_translator":false},"coordinates":null}
[End]

■注意事項■

同じ内容をツイートするとエラーとなる。
<標準出力>

[Start]
[Sun Nov 19 03:00:10 JST 2017]serialVersionUID: ******
[Sun Nov 19 03:00:10 JST 2017]debug: true
[Sun Nov 19 03:00:10 JST 2017]user: null
[Sun Nov 19 03:00:10 JST 2017]password: null
[Sun Nov 19 03:00:10 JST 2017]httpConf: MyHttpClientConfiguration{httpProxyHost='null', httpProxyUser='null', httpProxyPassword='null',
httpProxyPort=-1, httpConnectionTimeout=20000, httpReadTimeout=120000, prettyDebug=false, gzipEnabled=true}
[Sun Nov 19 03:00:10 JST 2017]httpStreamingReadTimeout: 40000
[Sun Nov 19 03:00:10 JST 2017]httpRetryCount: 0
[Sun Nov 19 03:00:10 JST 2017]httpRetryIntervalSeconds: 5
[Sun Nov 19 03:00:10 JST 2017]oAuthConsumerKey: ******
[Sun Nov 19 03:00:10 JST 2017]oAuthConsumerSecret:******
[Sun Nov 19 03:00:10 JST 2017]oAuthAccessToken: ******
[Sun Nov 19 03:00:10 JST 2017]oAuthAccessTokenSecret:******
[Sun Nov 19 03:00:10 JST 2017]oAuth2TokenType: null
[Sun Nov 19 03:00:10 JST 2017]oAuth2AccessToken: null
[Sun Nov 19 03:00:10 JST 2017]oAuth2Scope: null
[Sun Nov 19 03:00:10 JST 2017]oAuthRequestTokenURL: https://api.twitter.com/oauth/request_token
[Sun Nov 19 03:00:10 JST 2017]oAuthAuthorizationURL: https://api.twitter.com/oauth/authorize
[Sun Nov 19 03:00:10 JST 2017]oAuthAccessTokenURL: https://api.twitter.com/oauth/access_token
[Sun Nov 19 03:00:10 JST 2017]oAuthAuthenticationURL: https://api.twitter.com/oauth/authenticate
[Sun Nov 19 03:00:10 JST 2017]oAuth2TokenURL: https://api.twitter.com/oauth2/token
[Sun Nov 19 03:00:10 JST 2017]oAuth2InvalidateTokenURL: https://api.twitter.com/oauth2/invalidate_token
[Sun Nov 19 03:00:10 JST 2017]restBaseURL: https://api.twitter.com/1.1/
[Sun Nov 19 03:00:10 JST 2017]streamBaseURL: https://stream.twitter.com/1.1/
[Sun Nov 19 03:00:10 JST 2017]userStreamBaseURL: https://userstream.twitter.com/1.1/
[Sun Nov 19 03:00:10 JST 2017]siteStreamBaseURL: https://sitestream.twitter.com/1.1/
[Sun Nov 19 03:00:10 JST 2017]uploadBaseURL: https://upload.twitter.com/1.1/
[Sun Nov 19 03:00:10 JST 2017]dispatcherImpl: twitter4j.DispatcherImpl
[Sun Nov 19 03:00:10 JST 2017]asyncNumThreads: 1
[Sun Nov 19 03:00:10 JST 2017]loggerFactory: null
[Sun Nov 19 03:00:10 JST 2017]contributingTo: -1
[Sun Nov 19 03:00:10 JST 2017]includeMyRetweetEnabled: true
[Sun Nov 19 03:00:10 JST 2017]includeEntitiesEnabled: true
[Sun Nov 19 03:00:10 JST 2017]trimUserEnabled: false
[Sun Nov 19 03:00:10 JST 2017]jsonStoreEnabled: false
[Sun Nov 19 03:00:10 JST 2017]mbeanEnabled: false
[Sun Nov 19 03:00:10 JST 2017]userStreamRepliesAllEnabled: false
[Sun Nov 19 03:00:10 JST 2017]userStreamWithFollowingsEnabled: true
[Sun Nov 19 03:00:10 JST 2017]stallWarningsEnabled: true
[Sun Nov 19 03:00:10 JST 2017]applicationOnlyAuthEnabled: false
[Sun Nov 19 03:00:10 JST 2017]mediaProvider: TWITTER
[Sun Nov 19 03:00:10 JST 2017]mediaProviderAPIKey: null
[Sun Nov 19 03:00:10 JST 2017]mediaProviderParameters: null
[Sun Nov 19 03:00:10 JST 2017]daemonEnabled: true
[Sun Nov 19 03:00:10 JST 2017]instances: [ConfigurationBase{debug=true, user='null', password='null', httpConf=MyHttpClientConfiguration{httpProxyHost='null', httpProxyUser='null', httpProxyPassword='null', httpProxyPort=-1, httpConnectionTimeout=20000, httpReadTimeout=120000, prettyDebug=false, gzipEnabled=true}, httpStreamingReadTimeout=40000, httpRetryCount=0, httpRetryIntervalSeconds=5, oAuthConsumerKey='******', oAuthConsumerSecret='******', oAuthAccessToken='******', oAuthAccessTokenSecret='******', oAuth2TokenType='null', oAuth2AccessToken='null', oAuth2Scope='null', oAuthRequestTokenURL='https://api.twitter.com/oauth/request_token', oAuthAuthorizationURL='https://api.twitter.com/oauth/authorize', oAuthAccessTokenURL='https://api.twitter.com/oauth/access_token', oAuthAuthenticationURL='https://api.twitter.com/oauth/authenticate', oAuth2TokenURL='https://api.twitter.com/oauth2/token', oAuth2InvalidateTokenURL='https://api.twitter.com/oauth2/invalidate_token', restBaseURL='https://api.twitter.com/1.1/', uploadBaseURL='https://upload.twitter.com/1.1/', streamBaseURL='https://stream.twitter.com/1.1/', userStreamBaseURL='https://userstream.twitter.com/1.1/', siteStreamBaseURL='https://sitestream.twitter.com/1.1/', dispatcherImpl='twitter4j.DispatcherImpl', asyncNumThreads=1, loggerFactory='null', contributingTo=-1, includeMyRetweetEnabled=true, includeEntitiesEnabled=true, trimUserEnabled=false, jsonStoreEnabled=false, mbeanEnabled=false, userStreamRepliesAllEnabled=false, userStreamWithFollowingsEnabled=true, stallWarningsEnabled=true, applicationOnlyAuthEnabled=false, mediaProvider='TWITTER', mediaProviderAPIKey='null', mediaProviderParameters=null, daemonEnabled=true}]
[Sun Nov 19 03:00:10 JST 2017]Request:
[Sun Nov 19 03:00:10 JST 2017]GET https://api.twitter.com/1.1/account/verify_credentials.json
[Sun Nov 19 03:00:10 JST 2017]OAuth base string: GET&https%3A%2F%2Fapi.twitter.com%2F1.1%2Faccount%2
Fverify_credentials.json&oauth_consumer_key%******%26oauth_nonce%******%26oauth_signature_method%******%26o
auth_timestamp%3D1511028010%26oauth_token%******%26oauth_version%3D1.0
[Sun Nov 19 03:00:10 JST 2017]OAuth signature: ******
[Sun Nov 19 03:00:10 JST 2017]Authorization:******
[Sun Nov 19 03:00:10 JST 2017]X-Twitter-Client-URL: http://twitter4j.org/en/twitter4j-4.0.4.xml
[Sun Nov 19 03:00:10 JST 2017]X-Twitter-Client: Twitter4J
[Sun Nov 19 03:00:10 JST 2017]Accept-Encoding: gzip
[Sun Nov 19 03:00:10 JST 2017]User-Agent: twitter4j http://twitter4j.org/ /4.0.4
[Sun Nov 19 03:00:10 JST 2017]X-Twitter-Client-Version: 4.0.4
[Sun Nov 19 03:00:10 JST 2017]Response:
[Sun Nov 19 03:00:10 JST 2017]content-type: application/json;charset=utf-8
[Sun Nov 19 03:00:10 JST 2017]x-frame-options: SAMEORIGIN
[Sun Nov 19 03:00:10 JST 2017]HTTP/1.1 200 OK
[Sun Nov 19 03:00:10 JST 2017]x-response-time: 132
[Sun Nov 19 03:00:10 JST 2017]content-encoding: gzip
[Sun Nov 19 03:00:10 JST 2017]date: Sat, 18 Nov 2017 18:00:11 GMT
[Sun Nov 19 03:00:10 JST 2017]x-transaction: ******
[Sun Nov 19 03:00:10 JST 2017]cache-control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0
[Sun Nov 19 03:00:10 JST 2017]x-content-type-options: nosniff
[Sun Nov 19 03:00:10 JST 2017]expires: Tue, 31 Mar 1981 05:00:00 GMT
[Sun Nov 19 03:00:10 JST 2017]x-rate-limit-limit: 75
[Sun Nov 19 03:00:10 JST 2017]content-disposition: attachment; filename=json.json
[Sun Nov 19 03:00:10 JST 2017]x-twitter-response-tags: BouncerCompliant
[Sun Nov 19 03:00:10 JST 2017]x-twitter-response-tags: BouncerExempt
[Sun Nov 19 03:00:10 JST 2017]x-access-level: read-write
[Sun Nov 19 03:00:10 JST 2017]x-rate-limit-remaining: 73
[Sun Nov 19 03:00:10 JST 2017]last-modified: Sat, 18 Nov 2017 18:00:10 GMT
[Sun Nov 19 03:00:10 JST 2017]status: 200 OK
[Sun Nov 19 03:00:10 JST 2017]pragma: no-cache
[Sun Nov 19 03:00:10 JST 2017]x-connection-hash: ******
[Sun Nov 19 03:00:10 JST 2017]x-xss-protection: 1; mode=block
[Sun Nov 19 03:00:10 JST 2017]set-cookie: guest_id=******; Expires=Mon, 18 Nov 2019 18:00:10 UTC; Path=/; Domain=.twitter.com
[Sun Nov 19 03:00:10 JST 2017]set-cookie: lang=ja; Path=/
[Sun Nov 19 03:00:10 JST 2017]set-cookie: personalization_id="******"; Expires=Mon, 18 Nov 2019 18:00:10 UTC; Path=/; Domain=.twitter.com
[Sun Nov 19 03:00:10 JST 2017]content-length: 799
[Sun Nov 19 03:00:10 JST 2017]x-rate-limit-reset: 1511028793
[Sun Nov 19 03:00:10 JST 2017]server: tsa_m
[Sun Nov 19 03:00:10 JST 2017]strict-transport-security: max-age=631138519
[Sun Nov 19 03:00:11 JST 2017]{"location":"","default_profile":true,"profile_background_tile":false,"statuses_count":1,"lang":"ja",
"profile_link_color":"1DA1F2","id":******,"following":false,"protected":false,"favourites_count":0,"profile_text_color":"333333",
"description":"","verified":false,"contributors_enabled":false,"profile_sidebar_border_color":"C0DEED","name":"(株)エーフロンティア",
"profile_background_color":"F5F8FA","created_at":"Sat Nov 18 15:32:09 +0000 2017","is_translation_enabled":false,
"default_profile_image":true,"followers_count":0,"has_extended_profile":false,
"profile_image_url_https":"https://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png","geo_enabled":false,
"status":{"contributors":null,"text":"Twitter4Jテスト(^^)1","geo":null,"retweeted":false,"in_reply_to_screen_name":null,"truncated":false,
"lang":"ja","entities":{"symbols":[],"urls":[],"hashtags":[],"user_mentions":[]},"in_reply_to_status_id_str":null,"is_quote_status":false,"id":******,
"source":"<a href=\"http://www.a-fronter.jp\" rel=\"nofollow\">A-frontier-jp-TweetTest01<\/a>","in_reply_to_user_id_str":null,"favorited":false,
"in_reply_to_status_id":null,"retweet_count":0,"created_at":"Sat Nov 18 17:58:13 +0000 2017","in_reply_to_user_id":null,"favorite_count":0,
"id_str":"******","place":null,"coordinates":null},"profile_background_image_url":null,"profile_background_image_url_https":null,
"follow_request_sent":false,"entities":{"description":{"urls":[]}},"url":null,"utc_offset":null,"time_zone":null,"translator_type":"none",
"notifications":false,"profile_use_background_image":true,"friends_count":3,"profile_sidebar_fill_color":"DDEEF6",
"screen_name":"a_frontier_jp","id_str":"******",
"profile_image_url":http://abs.twimg.com/sticky/default_profile_images/default_profile_normal.png,"listed_count":0,"is_translator":false}
名前   :(株)エーフロンティア
表示名 :a_frontier_jp
フォロー数 :3
フォロワー数:0
[Sun Nov 19 03:00:11 JST 2017]Request:
[Sun Nov 19 03:00:11 JST 2017]POST https://api.twitter.com/1.1/statuses/update.json
[Sun Nov 19 03:00:11 JST 2017]OAuth base string: POST&https%3A%2F%2Fapi.twitter.com%2F1.1%2Fstatuses%2
Fupdate.json&include_entities%3Dtrue%26oauth_consumer_key%******%26oauth_nonce%******%26oauth_signature_method%******%
26oauth_timestamp%3D1511028011%26oauth_token%******%26oauth_version%3D1.0%26status%3DTwitter4J%******
[Sun Nov 19 03:00:11 JST 2017]OAuth signature: ******
[Sun Nov 19 03:00:11 JST 2017]Authorization:******
[Sun Nov 19 03:00:11 JST 2017]X-Twitter-Client-URL: http://twitter4j.org/en/twitter4j-4.0.4.xml
[Sun Nov 19 03:00:11 JST 2017]X-Twitter-Client: Twitter4J
[Sun Nov 19 03:00:11 JST 2017]Accept-Encoding: gzip
[Sun Nov 19 03:00:11 JST 2017]User-Agent: twitter4j http://twitter4j.org/ /4.0.4
[Sun Nov 19 03:00:11 JST 2017]X-Twitter-Client-Version: 4.0.4
[Sun Nov 19 03:00:11 JST 2017]Post Params: status=******=true
[Sun Nov 19 03:00:11 JST 2017]Response:
[Sun Nov 19 03:00:11 JST 2017]HTTP/1.1 403 Forbidden
[Sun Nov 19 03:00:11 JST 2017]content-type: application/json;charset=utf-8
[Sun Nov 19 03:00:11 JST 2017]x-frame-options: SAMEORIGIN
[Sun Nov 19 03:00:11 JST 2017]last-modified: Sat, 18 Nov 2017 18:00:11 GMT
[Sun Nov 19 03:00:11 JST 2017]status: 403 Forbidden
[Sun Nov 19 03:00:11 JST 2017]x-response-time: 126
[Sun Nov 19 03:00:11 JST 2017]content-encoding: gzip
[Sun Nov 19 03:00:11 JST 2017]date: Sat, 18 Nov 2017 18:00:11 GMT
[Sun Nov 19 03:00:11 JST 2017]x-transaction: ******
[Sun Nov 19 03:00:11 JST 2017]pragma: no-cache
[Sun Nov 19 03:00:11 JST 2017]cache-control: no-cache, no-store, must-revalidate, pre-check=0, post-check=0
[Sun Nov 19 03:00:11 JST 2017]x-connection-hash: ******
[Sun Nov 19 03:00:11 JST 2017]x-content-type-options: nosniff
[Sun Nov 19 03:00:11 JST 2017]x-xss-protection: 1; mode=block
[Sun Nov 19 03:00:11 JST 2017]expires: Tue, 31 Mar 1981 05:00:00 GMT
[Sun Nov 19 03:00:11 JST 2017]set-cookie: lang=ja; Path=/
[Sun Nov 19 03:00:11 JST 2017]set-cookie: personalization_id="******"; Expires=Mon, 18 Nov 2019 18:00:11 UTC; Path=/; Domain=.twitter.com
[Sun Nov 19 03:00:11 JST 2017]content-length: 85
[Sun Nov 19 03:00:11 JST 2017]content-disposition: attachment; filename=json.json
[Sun Nov 19 03:00:11 JST 2017]server: tsa_m
[Sun Nov 19 03:00:11 JST 2017]strict-transport-security: max-age=631138519
[Sun Nov 19 03:00:11 JST 2017]x-tsa-request-body-time: 0
[Sun Nov 19 03:00:11 JST 2017]x-twitter-response-tags: BouncerCompliant
[Sun Nov 19 03:00:11 JST 2017]x-access-level: read-write
[Sun Nov 19 03:00:11 JST 2017]{"errors":[{"code":187,"message":"Status is a duplicate."}]}

[End]
403:The request is understood, but it has been refused. An accompanying error message will explain why. This code is used when requests are being denied due to update limits (https://support.twitter.com/articles/15364-about-twitter-limits-update-api-dm-and-following).
message - Status is a duplicate.
code - 187

Relevant discussions can be found on the Internet at:

http://www.google.co.jp/search?q=2fc5b7cb or

http://www.google.co.jp/search?q=0ea287d2
TwitterException{exceptionCode=[2fc5b7cb-0ea287d2], statusCode=403, message=Status is a duplicate., code=187, retryAfter=-1, rateLimitStatus=null, version=4.0.4}
      at twitter4j.HttpClientImpl.handleRequest(HttpClientImpl.java:164)
      at twitter4j.HttpClientBase.request(HttpClientBase.java:57)
      at twitter4j.HttpClientBase.post(HttpClientBase.java:86)
      at twitter4j.TwitterImpl.post(TwitterImpl.java:1822)
      at twitter4j.TwitterImpl.updateStatus(TwitterImpl.java:207)
      at jp.a_frontier.twitter.TweetSample.main(TweetSample.java:25)

4.ソースコード

  ◎ tweetsample.java