[英]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:对于一个学校项目,我正在尝试使用 twitter4j 制作一个程序,该程序绘制一个图表,显示在开始日期和结束日期之间的某个区域内 twitter 上某个单词的使用情况,我通过实例化一个 Query 对象并设置开始直到日期到用户输入的日期,如下所示:
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()
由于当我取消注释最后一行 (setUntil) 时查询结果不返回任何推文 (Statuses),但是当我不包含 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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.