0

I want to collect all the tweets with this hashtag : "#Iran" for the first month of 2017, I tried this code but it won't work, please help.

    ConfigurationBuilder configurationBuilder = new ConfigurationBuilder()
            .setDebugEnabled(true)
            .setOAuthAccessTokenSecret(AccessTokenSecret)
            .setOAuthAccessToken(AccessToken)
            .setOAuthConsumerKey(ConsumerKey)
            .setOAuthConsumerSecret(ConsumerSecret);

    TwitterFactory twitterFactory = new TwitterFactory(configurationBuilder.build());
    Twitter twitter = twitterFactory.getInstance();




    Query query = new Query("#IRAN");

    query.setCount(100);

    query.setSince("2017-01-01");
    query.setUntil("2017-02-01");

    QueryResult queryResult = twitter.search(query);

    while (queryResult.hasNext()) {
        List<Status> status = queryResult.getTweets();
        for (Status status1 : status) {
            System.out.println("user : " + status1.getUser() + "\n" + status1.getText() + "\n" +
                    "ID : " + status1.getId() + "\n" + "Date : " + status1.getCreatedAt() +
            "\n\n*****************************************************");
        }
        query = queryResult.nextQuery();

    }
sadim ahman
  • 23
  • 1
  • 5

1 Answers1

0

Sadly you can't get tweets from the first month of 2017 with the search API. 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.

FeanDoe
  • 1,608
  • 1
  • 18
  • 30