Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Posting a tweet using Twitter4J.
<dependencies>
<dependency>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-core</artifactId>
<version>3.0.3</version>
</dependency>
<!-- ... -->
</dependencies>
400:The request was invalid. An accompanying error message will explain why. This is the status code will be returned during version 1.0 rate limiting(https://dev.twitter.com/pages/rate-limiting). In API v1.1, a request without authentication is considered invalid and you will get this response.
message - Bad Authentication data
code - 215
Relevant discussions can be found on the Internet at:
http://www.google.co.jp/search?q=b2b52c28 or
http://www.google.co.jp/search?q=10981ab8
TwitterException{exceptionCode=[b2b52c28-10981ab8], statusCode=400, message=Bad Authentication data, code=215, retryAfter=-1, rateLimitStatus=null, version=3.0.3}
at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:177)
at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:61)
at twitter4j.internal.http.HttpClientWrapper.post(HttpClientWrapper.java:98)
at twitter4j.TwitterImpl.post(TwitterImpl.java:1871)
at twitter4j.TwitterImpl.updateStatus(TwitterImpl.java:241)
at twitter.TwitterAPI.postExchangeRate(TwitterAPI.java:16)
...
401:Authentication credentials (https://dev.twitter.com/pages/auth) were missing or incorrect. Ensure that you have set valid consumer key/secret, access token/secret, and the system clock is in sync.
message - Could not authenticate you
code - 32
Relevant discussions can be found on the Internet at:
http://www.google.co.jp/search?q=b2b52c28 or
http://www.google.co.jp/search?q=10981ab8
TwitterException{exceptionCode=[b2b52c28-10981ab8], statusCode=401, message=Could not authenticate you, code=32, retryAfter=-1, rateLimitStatus=null, version=3.0.3}
at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:177)
at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:61)
at twitter4j.internal.http.HttpClientWrapper.post(HttpClientWrapper.java:98)
at twitter4j.TwitterImpl.post(TwitterImpl.java:1871)
at twitter4j.TwitterImpl.updateStatus(TwitterImpl.java:241)
at twitter.TwitterAPI.postExchangeRate(TwitterAPI.java:16)
...
401:Authentication credentials (https://dev.twitter.com/pages/auth) were missing or incorrect. Ensure that you have set valid consumer key/secret, access token/secret, and the system clock is in sync.
{"request":"\/1.1\/statuses\/update.json","error":"Read-only application cannot POST"}
Relevant discussions can be found on the Internet at:
http://www.google.co.jp/search?q=b2b52c28 or
http://www.google.co.jp/search?q=10981ab8
TwitterException{exceptionCode=[b2b52c28-10981ab8], statusCode=401, message=null, code=-1, retryAfter=-1, rateLimitStatus=null, version=3.0.3}
at twitter4j.internal.http.HttpClientImpl.request(HttpClientImpl.java:177)
at twitter4j.internal.http.HttpClientWrapper.request(HttpClientWrapper.java:61)
at twitter4j.internal.http.HttpClientWrapper.post(HttpClientWrapper.java:98)
at twitter4j.TwitterImpl.post(TwitterImpl.java:1871)
at twitter4j.TwitterImpl.updateStatus(TwitterImpl.java:241)
at twitter.TwitterAPI.postExchangeRate(TwitterAPI.java:16)
...
debug=true
oauth.consumerKey=ZeWTr73DdFEj5w4gjzdw
oauth.consumerSecret=NgxpXhvGr887RLYb705OzwKbpyBx23FsDNF5FnD0
oauth.accessToken=472356387-ireq8dXHKr08018nhqSb0Vp3gVI77UD4r3mLGSXb
oauth.accessTokenSecret=blUsP2dIdfjLyiDSk65fxV6qCqJaDU3TdTrQ2W4qjYG
Twitter twitter = TwitterFactory.getSingleton();
try {
Status status = twitter.updateStatus("A tweet from twitter4j. #test");
System.out.println("Successfully updated the status to [" + status.getText() + "].");
} catch (TwitterException te) {
te.printStackTrace();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment