Skip to main content


Showing posts from September, 2014

Using Twitter search API in Java

If you are reading this, I assume you are aware about Twitter APIs. If you are new to this API, I suggest you read the API documentation (which is quite good BTW!)

This simple program of mine uses Twitter search API to get "positive" tweets for a search string. It aims to retrieve all the search results (tweets) and hence has to make multiple calls to REST API, for which it uses max_id (explained later).

Let me give an overview of all the request parameters that we have specified in the URL (Twitter API URL):

q=%23SearchString: #SearchString count=100: Number of tweets you want the API to return in one call.include_entities=false: Exclude details of entities in the JSON response. You can set it to true if you want.max_id: Since we want more than 100 tweets, we are invoking the API multiple times and giving the id of last tweet returned in previous invocation as 'max_id' and asking Twitter to give 100 tweets prior to this tweet. e.g. First call returned tweets with Twe…