UPDATE Twitter Status in java code
Step 1:
If have an account in Twitter.Visit this link
https://dev.twitter.com/apps/new . I not create the Twitter account and then visit this
https://dev.twitter.com/apps/new.
Step 2:
Fillup the follow Fields and Click the "Create Yout Twitter Application" Button
Step 3: [Getting consumerKey, consumerSecret, accessToken, accessSecret ]
Then click
https://dev.twitter.com/apps link and move to "oAuth setting " then get the consumerKey, consumerSecret, accessToken, accessSecret.
Step 4:
Download latest api for Twitter
Step 5:
Paste this below code
CODE:
import twitter4j.*;
import twitter4j.auth.AccessToken;
import twitter4j.auth.RequestToken;
import twitter4j.conf.ConfigurationBuilder;
import java.util.List;
/**
* Created with IntelliJ IDEA.
* User: hduser
* Date: 11/11/13
* Time: 4:09 PM
* To change this template use File | Settings | File Templates.
*/
public class MainTwitter {
public static void main(String[] args){
String testPost = "Visit www.peopleuseit.blogspot.com";
String consumerKey="h5oJt4PHzJpBVS0hDmQ";
String consumerSecret="bToKD9z8UbkkzODjSc4NNDVsR39I2ePlowvZU";
String accessToken="368187981-OBN7TZA1aQT3xlrkbLB5xO2AkmVbjSDX8RoK";
String accessSecret="xkZkbwG3fgOJt2wwVtc5CMSN8v6FoagSJuKXdDfPH";
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey(consumerKey)
.setOAuthConsumerSecret(consumerSecret)
.setOAuthAccessToken(accessToken)
.setOAuthAccessTokenSecret(accessSecret);
try {
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
AccessToken accestoken = new AccessToken(accessToken, accessSecret);
twitter.setOAuthAccessToken(accestoken);
Status status = twitter.updateStatus(testPost);
System.out.println("it worked!");
if (status.getId() == 0) {
System.out.println("Error occured while posting tweets to twitter");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Step 7:
Run the Program