Searching tweet before and after provided dates

Searching tweet before and after provided dates


Posted in : Java Posted on : October 22, 2011 at 4:27 PM Comments : [ 0 ]

In this section, you can learn how to search a tweet before & after provided dates using twitter4j library.

Searching tweet before and after provided dates

In this section, you can learn how to search a tweet before & after provided dates using twitter4j library.

In the below example, you need to put the after date into since( ) and before date into  until( ) function.

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

Code for the above is given below :

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>
<%
//Getting tweet after 2011-09-15 and befor 2011-09-16 with a particular search topic
out.println("<h3>Getting tweet after 2011-10-15 and before 2011-10-16 with a particular search topic : </h3>");
Twitter twitter = new TwitterFactory().getInstance();
Query query2 =new Query("#clt20").since("2011-10-15").until("2011-10-16").rpp(100);
QueryResult result2 = twitter.search(query2);
int i=1;
for (Tweet tweet : result2.getTweets()) {
out.println("<img src='"+tweet.getProfileImageUrl()+"'>"+"<b>("+i+") "+tweet.getFromUser()+"("+tweet.getCreatedAt()+")"+"</b>" + " : " + tweet.getText()+"<br/>");
i++;
}
%>
</body>
</html>

OUTPUT

Download Source  Code

Go to Topic «PreviousHomeNext»

Your Comment:


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

 
Tutorial Topics