Java - Post to Twitter
I've written a simple web application, which I want to be able to post tweets.
I have seen some java libraries for working with Twitter, but they all seem like too much of work for something that is seemingly simple. Is it possible 开发者_高级运维that I am missing something?
Is there any simple way to post a tweet in twitter from a web-app in java with only a few lines of code?
By trying to resolve the compilation problems in jzd's reply, here's what i came up with:
public static void sendToTwitter(String tweet) {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey("---")
.setOAuthConsumerSecret("---")
.setOAuthAccessToken("---")
.setOAuthAccessTokenSecret("---");
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter t = tf.getInstance();
try {
t.updateStatus(tweet);
} catch (TwitterException te) {
te.printStackTrace();
}
}
And it works just as i wanted it to. Thank you very much.
Well using Twitter4J it is fairly easy:
TwitterFactory.getInstance(username,password).updateStatus("This goes to Twitter");
精彩评论