Teja
Teja

Reputation: 341

Posting tweets from a java application

I want to auto tweet from a java application. What is the simplest way to do it? Can i avoid using libraries like Twitter4j etc.,

I need an implementation for a simple api like

Tweet(username, password, message)..

Thank you.

Upvotes: 6

Views: 10514

Answers (4)

Goran Jovic
Goran Jovic

Reputation: 9508

I want to auto tweet from a java application.

I hope you are not spamming.. :D

Try this one: http://code.google.com/p/java-twitter/

You can wrap the example code into:

public void tweet(String username, String password, String message){

Api api = Api.builder().username(username).password(password).build();
api.updateStatus(message).build().post();

}

And then call it as tweet.(username,pass,message)

Looks simple to me.

Upvotes: 1

Ganesh
Ganesh

Reputation: 1654

I recommend you to use twitter4j and using this you can create oAuth requests easily. Twitter rate limits apply to desktop application and it is 150/hour. Twitter does not support basic authentication with username and password anymore.

You are required to create an application in twitter and using the consumer key and secret only you can access your twitter account.

If you are going to access the twitter by a desktop application then you have to select Application Type: as "Client" while creating the application. Then you can use the syntax below to update your status in twitter

 ConfigurationBuilder cb = new ConfigurationBuilder();
            cb.setDebugEnabled(true)
                .setOAuthConsumerKey(consumerKey)
                .setOAuthConsumerSecret(consumerSecret)
                .setOAuthAccessToken(oAuthAccessToken)
                .setOAuthAccessTokenSecret(oAuthAccessTokenSecret);
            TwitterFactory tf = new TwitterFactory(cb.build());
            Twitter twitter = tf.getInstance();
                    twitter.updateStatus("This is a test message"); //ThrowsTwitterException

I hope this helps you... Please let me know if this is not the answer you were looking for. Implementing your own oAuth request involve creating signature that for me was complicated and it is sensitive to time and time format that we send.

Upvotes: 13

revdrjrr
revdrjrr

Reputation: 1045

Spring Social? I saw a demo of it at SpringOne - looked pretty cool, although I personally do not have a use for it, and therefore haven't done much besides read about it. You get some OAuth capability and templates for interacting with the major social networking sites out of the box.

Upvotes: 0

Berin Loritsch
Berin Loritsch

Reputation: 11463

Twitter has a REST web API, and a lot of documentation. For reference:

http://dev.twitter.com/doc

While you don't necessarily need Twitter4J, it does make it easier. Otherwise you would need to assemble your own URL requests and take care of authentication. They offer more than one style:

http://dev.twitter.com/pages/auth_overview

Traditionally, OAuth is the preferred style for desktop application to web server integration--but that protocol is a bit complicated.

There's nothing that says you can't create your Tweet() method to hide away the details of using Tweet4J or hand-rolling the request yourself.

Upvotes: 2

Related Questions