This is continuation of article Login With Twitter Using Java. By using Twitter OAuth features, If you want to update status of user from your java web application, This article will help you. Suppose if you create a news sharing website, Your website will get more traffic if users share those news on their twitter's timeline. They can do that directly from your application if they given access to your application. Twitter is having java library twitter4j to access twitter services. Download twitter4j and add those jars to WEB-INF folder.
---   Click here to see demo  ---  Download eclipse code ---


I have provided sample project here, download it. Open and give your twitter app credentials, database credentials. Create MySQL database schema with name "demos". Created below specified table. Import this project into Eclipse, add it to tomcat server, run index.html

There are 2 types of Update Status features are there.  
  1. Update status to your own profile using access token and access token secret which were generated manually
  2. Update status on user's timeline using oauth access token and access token secret that were saved in database

Process - Oauth Status Update

  1. Register your application in twitter developers page
  2. Provide access link to user ( Generate link using Twitter4j ) 
  3. User will be redirected to twitter access page. User will give permission to application
  4. Access token will be sent to Callback URL
  5. Get access token and store it in database
  6. Whenever you want to update status on user's timeline, get access token from access token secret from database and update status using them
   // configure twitter object with consumer key and consumer secret 
   ConfigurationBuilder cb = new ConfigurationBuilder();
   TwitterFactory tf = new TwitterFactory(;
   Twitter twitter = tf.getInstance();
   // get user details from by user id
   UserPojo user = TwitterDAO.selectUser(4);
   // set access token and access token secret and user id
   AccessToken accessToken1 = new AccessToken(user.getAccess_token(), user.getAccess_token_secret(), user.getTwitter_User_id());
   // update status from
   twitter.updateStatus("Sample tweet from standalone java");

Process - Status Update To Your Own Profile

If you want to update status to your own profile, you can do it with default access token and access token secret. Observe below screenshot.  
Build AccessToken object with above access token and access token secret and user id. Update status as like above


  1. How can I ask other users to login here by twitter . this application only allows to login into my twitter account but I have to create a app where my sites customer can login via twitter

  2. Having a high status can be pleasant because it brings freedom, comfort, more time, flattery, special attention, privileges and a sense of importance and can be valued as one of life's most important qualities. Status

  3. I was reading some of your content on this website and I conceive this internet site is really informative ! Keep on putting up. best whatsapp status

  4. Gambling is not a recent phenomenon as there have been records of their existence as early as in 2300 BC. However, gambling did not become organised in the form of casinos until the 19th century.



Popular Posts