2

When I add since & until restrictions to my Query, nothing returns as result despite there are many tweets during this duration for my keyword. The result is still same if I do not use the since restriction.

How can I retrieve tweets in a time range using twitter4j?

Here is a snippet from my implementation:

Query query = new Query();
query.setQuery(topic + " +exclude:retweets");
query.setCount(100);
query.setLang("en");
query.setSince("2015-08-29");
query.setUntil("2015-11-29");
QueryResult result = twitter.search(query);
List < Status > tweets = result.getTweets();

ps. I am using the latest stable version of twitter4j which is 4.0.4.

talha06
  • 6,206
  • 21
  • 92
  • 147

1 Answers1

5

Sadly you can't get tweets from that time range. From the documentation:

The Search API is not complete index of all Tweets, but instead an index of recent Tweets. At the moment that index includes between 6-9 days of Tweets.

So, you can only get recent tweets from the search API. Be careful too with the data beacuse it's about relevance not completeness, from the same documentation:

Before getting involved, it’s important to know that the Search API is focused on relevance and not completeness. This means that some Tweets and users may be missing from search results. If you want to match for completeness you should consider using a Streaming API instead.

If you really need older tweets you will have to get them from other sources like Gnip. Otherwise you will have to approach differently your problem.

If you have the names (or id's) of all the users that you want to get info you could get the timelines from each user getting up to 3200 tweets.

Community
  • 1
  • 1
FeanDoe
  • 1,608
  • 1
  • 18
  • 30
  • As I know, **twitter4j Streaming API does not let to set time range** since its target is the live streaming data. It seems **Gnip** is a commercial product; I need an open source solution. – talha06 Jan 07 '16 at 06:55
  • 1
    Twitter4j let you set the range but just for the Twitter Search API (which only let you get few days back). As far as I know there wasn't an open source solution to get older tweets, a couple months ago you could do tricks with Topsy but the service is dead – FeanDoe Jan 07 '16 at 11:43