Twitter twitter = new Twitter();
RequestToken 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 accessToken = null;
BufferedReader br = new BufferedReader(new 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("Hit enter when it's done.[Enter]:");
br.readLine();
try{
accessToken = requestToken.getAccessToken();
} 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());
Status status = twitter.updateStatus(args[0]);
System.out.println("Successfully updated the status to [" + status.getText() + "].");
System.exit(0);
} catch (TwitterException te) {