Searching tweets from a particular user

Searching tweets from a particular user


Posted in : Java Posted on : October 20, 2011 at 6:57 PM Comments : [ 0 ]

In this section, you can learn how to view the tweets from a specific user using twitter4j library.

Searching tweets from a particular user

In this section, you can learn how to view the tweets from a specific user using twitter4j library.

Twiiter4j is the unofficial java library for the Twitter API. You can easily integrate twitter4j with your java application. It supports Jdk1.4.2 or later. It also supports Android platform and Google APP Engine.

The official for twiiter4j library is http://twitter4j.org . You can download twitter4j library from here.

For searching tweet you need only one jar file. i.e. twitter4j-core-2.2.5-SNAPSHOT.jar

CODE

In the given below example, we are going to search all the tweets from a particular user. Here, we are going to fetch all the tweets from user having profile name "imsrk". Given below the code :

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1" import="java.sql.*,twitter4j.*"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
// Searching tweet from a particular user
System.out.println("Searching tweet of a particular user------------------------------>>");
Query query3 = new Query("from:imsrk").rpp(100);
QueryResult result3 = twitter.search(query3);
for (Tweet tweet3 : result3.getTweets()) {
out.println("<img src='"+tweet.getProfileImageUrl()+"'>"+"<b>("+i+") "+tweet.getFromUser()+"("+tweet.getCreatedAt()+")"+"</b>" + " : " + tweet.getText()+"<br/>");
i++;
}
%>
</body>
</html>

The above code will show you only the last 8 days tweets from user. This is because Twitter have restriction over fetching tweet using Twitter API. It will show the 100  top tweet from user with in 8 days. If user tweeted less than 100 in passed 8 days, then it will show all the tweets within 8 days.

OUTPUT

Download Source Code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics