Its so simple to create a java client to read twitter messages using some third party libraries like Twitter4j etc. You did not mention which tweets you wanted to read whether your own tweets or someone else's, anyway I followed this blog and got my work done :)
- Crate a Twitter application on https://apps.twitter.com/app/new and get your consumer key. (Follow the mentioned blog if you struck somewhere.)
- Using the Twitter4j API get the authorization URL, hit it and get the PIN. (The code required is mentioned below for your ref)
- Input the pin and get access tocken (refer below code)
- That's all now we can read or update twitter feeds. (Based on the access level you set while creating twitter application)
Sample code:
Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(CONSUMER_KEY, CONSUMER_KEY_SECRET);
RequestToken requestToken = twitter.getOAuthRequestToken();
System.out.println("Authorization URL: \n"
+ requestToken.getAuthorizationURL());
AccessToken accessToken = null;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try{
System.out.print("Hit above Authorization URL and Input PIN here: ");
String pin = br.readLine();
accessToken = twitter.getOAuthAccessToken(requestToken, pin);
} catch (TwitterException te) {
System.out.println("Failed to get access token, caused by: "
+ te.getMessage());
}
System.out.println("Access Token: " + accessToken.getToken());
System.out.println("Access Token Secret: "
+ accessToken.getTokenSecret());
// updating twitter status
twitter.updateStatus("hi.. im updating this using Namex Tweet for Demo");
System.out.println("\nReading Twitter Timeline:");
// I'm reading your timeline
ResponseList list = twitter.getHomeTimeline();
for (Status each : list) {
System.out.println("Sent by: @" + each.getUser().getScreenName()
+ " - " + each.getUser().getName() + "\n" + each.getText()
+ "\n");
}
Check it and comment here if you face any issues.