Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Posting tweets from a java application

Tags:

java

twitter

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.

like image 757
Teja Avatar asked Dec 10 '10 20:12

Teja


1 Answers

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.

like image 160
Ganesh Avatar answered Oct 18 '22 06:10

Ganesh