简体   繁体   中英

How do I put an end date to a Twitter4J Query search result in Java?

For a school project I'm trying to make a program using twitter4j that plots a graph displaying the usage of a certain word on twitter within a certain region between a start and end date, I do this by instantiating a Query object and setting the start and until dates to dates inputted by the user like this:

  Query q = new Query(word);
  q.setCount(100);
  q.setGeoCode(loc,100,Query.MILES);
  q.setSince(start + "-1-1");
  //q.setUntil(end + "-12-12"); NOT WORKING!!

Does anyone know what I'm doing wrong? As the query result returns no tweets (Statuses) when I uncomment the last line (setUntil) but it works fine when I don't include the setUntil()

This code is working for me. I hope this example clarifies your doubt.

 Query query = new Query(hashtag);
 query.setSince("yyyy-mm-dd");
 query.setUntil("yyyy-mm-dd");
 query.setCount(100);
           
 //Execute the search method in the twitter object. The results are contained in a QueryResult object that contains one object Status per Tweet
 QueryResult result = twitter.search(query);
 out.println(result.getTweets().size());
 for (Status status : result.getTweets()) {
     out.println("@" + status.getUser().getScreenName() + ":" + status.getText());
     out.println();
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM