Original article: Copyright * Copyright 2007 Yusuke Yamamoto ** licensed under the Apache license, version 2.0 (the "License"); * you may not use this file license t in compliance with the license. * You may obtain a copy of the license at ** http://www.apache.org/licenses/LICENSE-2.0 ** unless req Uired by applicable law or agreed to in writing, software * distributed under the license is distributed on an "as is" basis, * Without warranties or conditions of any kind, either express or implied. * See the license for the specific language governing permissions and * limitations under the license. */package twitter4j. examples. tweets; import twitter4j. status; import twitter4j. twitter; import twit Ter4j. twitterexception; import twitter4j. twitterfactory; import twitter4j. auth. accesstoken; import twitter4j. auth. requesttoken; import Java. io. bufferedreader; import Java. io. ioexception; import Java. io. inputstreamreader;/*** example application that uses oauth method to acquire access to your account. <br> * This application uses strates how to use oauth method with twitter4j. <br> ** @ author Yusuke Yama Moto-Yusuke at mac.com */public final class updatestatus {/*** usage: Java twitter4j. examples. tweets. updatestatus [text] ** @ Param ARGs message */public static void main (string [] ARGs) {If (ARGs. length <1) {system. out. println ("Usage: Java twitter4j. examples. tweets. updatestatus [text] "); system. exit (-1);} Try {Twitter = new twitterfactory (). getinstance (); try {// GET request Tok En. // This will throw illegalstateexception if access token is already available requesttoken = Twitter. getoauthrequesttoken (); system. out. println ("got request token. "); system. out. println ("request token:" + requesttoken. gettoken (); system. out. println ("request token secret:" + requesttoken. gettokensecret (); accesstoken = NULL; bufferedreader BR = new bufferedreader (ne W inputstreamreader (system. in); While (null = accesstoken) {system. out. println ("Open the following URL and grant access to your account:"); system. out. println (requesttoken. getauthorizationurl (); system. out. print ("Enter the PIN (if available) and hit Enter after you granted access. [pin]: "); string pin = BR. readline (); try {If (pin. length ()> 0) {accesstoken = Twitter. getoauthaccesstoken (reques Ttoken, pin);} else {accesstoken = Twitter. getoauthaccesstoken (requesttoken) ;}} catch (twitterexception Te) {If (401 = tE. getstatuscode () {system. out. println ("unable to get the access token. ");} else {Te. printstacktrace () ;}} system. out. println ("got access token. "); system. out. println ("access token:" + accesstoken. gettoken (); system. out. println ("access token secret:" + accesstoken. Gettokensecret ();} catch (illegalstateexception IE) {// access token is already available, or consumer key/secret is not set. If (! Twitter. getauthorization (). isenabled () {system. out. println ("oauth consumer key/secret is not set. "); system. exit (-1) ;}} status = Twitter. updatestatus (ARGs [0]); system. out. println ("successfully updated the status to [" + status. gettext () + "]. "); system. exit (0);} catch (twitterexception Te) {Te. printstacktrace (); system. out. println ("failed to get timeline:" + Te. getmessage (); system. exit (-1);} catch (ioexception IOE) {IOE. printstacktrace (); system. out. println ("failed to read the system input. "); system. exit (-1 );}}}