Searching tweets having particular hash tag

Searching tweets having particular hash tag


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

In this section, you will learn how to search tweet from Twitter using twitter4j java library.

Searching tweets having particular hash tag

In this section, you  will learn how to search tweet from Twitter using twitter4j java library.

In the below tutorial you will learn how to search tweets having particular hashtag.

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

Given below the JSP code which is displaying 100 top tweet related to the hash tag arranged by latest dates :

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>
<%
//Passing hastag
String tag=#CLT20;

//Dispalying 100 tweet related to upper hashtag
out.println("<h2>"+"The Tweets related to "+tag+" are given below :"+"</h2>");
Twitter twitter = new TwitterFactory().getInstance();
Query query = new Query(tag).rpp(100);
QueryResult result = twitter.search(query);
int i=1;
for (Tweet tweet : result.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