Presentation is loading. Please wait.

Presentation is loading. Please wait.

Development of Twitter Applications Part 7. Search API

Similar presentations


Presentation on theme: "Development of Twitter Applications Part 7. Search API"— Presentation transcript:

1 Development of Twitter Applications Part 7. Search API
Dr. Myungjin Lee

2 Search API Search REST API Limitation
find and return a collection of relevant Tweets based on matching a specified query Limitation not complete index of all Tweets, but instead an index of recent 6-9 days of Tweets cannot find Tweets older than about a week. limited due to complexity not support authentication meaning all queries are made anonymously. focused in relevance and not completeness limited to 1,000 characters in query length, including any operators.

3 Search Operator Example Finds tweets... twitter search
containing both "twitter" and "search". This is the default operator "happy hour" containing the exact phrase "happy hour" love OR hate containing either "love" or "hate" (or both) beer -root containing "beer" but not "root" #haiku containing the hashtag "haiku" from:twitterapi sent from the to:twitterapi sent to the place:opentable:2 about the place with OpenTable ID 2 place:247f43d441defc03 about the place with Twitter ID 247f43d441defc03 @twitterapi superhero since: containing "superhero" and sent since date " " twitterapi until: containing "twitterapi" and sent before the date " ". movie -scary :) containing "movie", but not "scary", and with a positive attitude. flight :( containing "flight" and with a negative attitude. traffic ? containing "traffic" and asking a question. hilarious filter:links containing "hilarious" and with a URL. news source:tweet_button containing "news" and entered via the Tweet Button

4 GET search/tweets Resource URL Parameters Other Information
Parameters Other Information Requests per rate limit window: 180/user, 450/app Authentication: Required Response Object: Tweets q required A UTF-8, URL-encoded search query of 1,000 characters maximum, including operators. Queries may additionally be limited by complexity. geocode optional Returns tweets by users located within a given radius of the given latitude/longitude. lang Restricts tweets to the given language, given by an ISO code. Language detection is best-effort. result_type Optional. Specifies what type of search results you would prefer to receive. The current default is "mixed." Valid values include: * mixed: Include both popular and real time results in the response. * recent: return only the most recent results in the response * popular: return only the most popular results in the response. count The number of tweets to return per page, up to a maximum of 100. Defaults to 15. until Returns tweets generated before the given date. Date should be formatted as YYYY-MM-DD. since_id Returns results with an ID greater than (that is, more recent than) the specified ID. max_id Returns results with an ID less than (that is, older than) or equal to the specified ID. include_entities The entities node will be disincluded when set to false. callback If supplied, the response will use the JSONP format with a callback of the given name.

5 Twitter4J Classes for Search
SearchResource Interface Methods QueryResult search(Query query) Query Class A data class represents search query. Constructor Query() Query(java.lang.String query) void setCount(int count) void setGeoCode(GeoLocation location, double radius, java.lang.String unit) void setLang(java.lang.String lang) void setLocale(java.lang.String locale) void setMaxId(long maxId) void setQuery(java.lang.String query) void setResultType(java.lang.String resultType) MIXED, POPULAR, RECENT void setSince(java.lang.String since) void setSinceId(long sinceId) void setUntil(java.lang.String until)

6 Twitter4J Classes for Search
QueryResult Interface A data interface representing search API response Methods int getCount() long getMaxId() java.lang.String getQuery() long getSinceId() java.util.List<Status> getTweets() boolean hasNext() Query nextQuery()

7 Searching Tweets import java.util.List; import twitter4j.Query;
import twitter4j.QueryResult; import twitter4j.Status; import twitter4j.Twitter; import twitter4j.TwitterException; import twitter4j.TwitterFactory; public class TwitterSearch { Twitter twitter = null; public TwitterSearch() { this.twitter = TwitterFactory.getSingleton(); this.twitter.setOAuthConsumer(TwitterAccessToken.consumerKey, TwitterAccessToken.consumerSecret); this.twitter.setOAuthAccessToken(TwitterAccessToken.loadAccessToken()); } public static void main(String args[]) throws TwitterException { TwitterSearch tt = new TwitterSearch(); Query q = new Query(); q.setQuery("GentleMan"); q.setResultType(Query.RECENT); q.setCount(100); QueryResult qr = tt.twitter.search(q); List<Status> tweets = qr.getTweets(); for (int i = 0; i < tweets.size(); i++) { Status tweet = tweets.get(i); System.out.println("Text: " + tweet.getText() + ", " + tweet.getCreatedAt() + ", " + tweet.getRetweetCount());


Download ppt "Development of Twitter Applications Part 7. Search API"

Similar presentations


Ads by Google