Tweet with Java library
How to auto Tweet on Twitter using Java?
Twitter4J is a Java library for Twitter API, using which you can communicate with Twitter directly through your Java application
Rahul Sah
Wednesday, August 19, 2009
  • Email
  • Print
  • Comments
  • RSS
  • Digg
  • Delicious
  • Reditt


";
for(int i=0; i < statuses.size() ; i++) {
Status status1 = (Status)statuses.get(i);
user = status1.getUser().getName();
text = status1.getText();
htmlPage += ""+user+":";
htmlPage += ""+text+"";
htmlPage += "
";
}
outputToBrowser.println(htmlPage);
String htmlPage2 = "
";
htmlPage2 += "
Return to Main Page";
htmlPage2 += "
";
outputToBrowser.println(htmlPage2);
outputToBrowser.close();
} catch (TwitterException ex) {
ex.printStackTrace();
}
}

Formatting the Timeline
The getFriendsTimeline() method returns the list of statuses, and we can iterate through those statuses list to get each status's user name and the text message of the status.

Using response.getWriter() we can display the output as text on the browser, but not in a formatted style. To present the output in as a HTML page we use the PrintWriter class of the java.io package.

This class implements all of the print methods found in PrintStream, and is used for print formatted representations for a text output stream. The PrintWriter will stream the output through the getOutputStream() method of the ResponseServlet. We will set the content type of the response being sent to the client as text/html through the ResponseServlet's setContentType() method.

Conclusion
Thus we have created a servlet based application that can send user updates to twitter and fetch user's friends updates back. Though in our example we have hard-coded the TwitterID and password, but while creating an application you can pass the user's Twitter ID and password through a JSP form to the servlet.

©PCQuest
<<PREVIOUS       



Name
 
Email
Comment Here
 
Code Verification 
   

Skip Navigation Links.
Collapse <div class='CommentsContainer'>Read Comments</div>
Read Comments
RAHUL said on 7/23/2010 11:47:32 AM:
thanks mate i was just wondering whethar i could integrate twitter in my final year project.
to RAHUL
tim sweeney said on 10/4/2009 2:49:59 AM:
very weel done this desciption should help anyone with basic java skills to write some cool API
to tim sweeney
Muni said on 8/20/2009 12:29:55 PM:
Nice article. Please write more tutorials like this than publishing news.
to Muni
  
 
 




Copyright © CyberMedia India Online Ltd.
All rights reserved. Usage of content from web site is subject to Terms and Conditions.