Reputation: 12213
I have this code
PrintWriter out = response.getWriter();
String username="twitterapi";
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey("zRQs******yDLJuQ")
.setOAuthConsumerSecret("W368******************DsWya56uk")
.setOAuthAccessToken("124529**************EQ2XAfAQShzSWExwMoOS")
.setOAuthAccessToken("UiH**********************k6UuCPveirdF");
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
User user = null;
try {
user = twitter.showUser(username);
} catch (TwitterException ex) {
Logger.getLogger(Twitter_Final.class.getName()).log(Level.SEVERE, null, ex);
}
if (user.getStatus() != null) {
out.println("@" + user.getScreenName() + " - " + user.getDescription());
} else {
// protected account
out.println("@" + user.getScreenName());
}
But i get this the kwown error message "Authentication credentials are missing. See http://twitter4j.org/en/configuration.html for the detail."
I have read similar questions here but i cant see where the problem in my code is. Can you?
Upvotes: 3
Views: 3130
Reputation: 8617
The problem is in your ConfigurationBuilder
, you are setting OAuthAccessToken
twice but never OAuthAccessTokenSecret
:
Just change your code to:
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey(YOUR_KEY)
.setOAuthConsumerSecret(YOUR_SECRET)
.setOAuthAccessToken(ACCESS_TOKEN)
.setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET);
It would work!
Upvotes: 3