Java - Post to Twitter

I wrote a simple web application that I want to send tweets.

I had seen some java libraries for working with Twitter, but they all seem to be too much work for something seemingly simple. Is it possible that I missed something?

Is there an easy way to post a twitter tweet from a web application in java with only a few lines of code?

+5
source share
2 answers

Trying to solve compilation problems in jzd's answer, here is 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 the way I wanted it. Thank you very much.

+4
source

Well, using Twitter4J, it's pretty easy:

TwitterFactory.getInstance(username,password).updateStatus("This goes to Twitter");
0
source

All Articles