How to retrieve more than 100 tweets with the Twitter API and Twitter4J

The twitter4j wraps the twitter API and provides you access to public_timeline and retrieve latest tweets. The twiter API returns only the last 20 tweets. For retrieving old tweets you may have to request the timeline a number of times. Twitter does not provide any other option (I guess you can use the streaming API to get the tweets pushed, but you can’t get more than 20 older messages). In order to find older tweets, you can use twitter4j library where you can search for Tweets using Query class and Twitter.search(twitter4j.Query) method. Below is the example code which can be used to search tweets and write retrieved tweets in a .csv file. Writing in a file needs little improvements.

I am also sharing a small code to use the twitter streaming API which helps to get the tweets pushed, but you can’t get more than 20 older messages.

No Responses

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.