[英]Twitter4j counting the number of tweets found
这是我查找主题标签的方法:
void getNewTweets()
{
//try the search
try
{
Query query = new Query(searchString);
//get the last 50 tweets
query.count(2);
QueryResult result = twitter.search(query);
tweets = result.getTweets();
System.out.println(tweets);
}
//if there is an error then catch it and print it out
catch (TwitterException te)
{
System.out.println("Failed to search tweets: " + te.getMessage());
System.exit(-1);
}
}
我正在使用 Twitter4j 库。 我如何计算找到的推文数量?
您还可以使用QueryResult.getCount()
函数。
Query query = new Query(searchString);
QueryResult result = twitter.search(query);
int count = results.getCount();
System.out.println("tweet count: " + count);
将推文存储在 ArrayList 中并获取 ArrayList 的大小以显示推文的数量。
ArrayList tweets = (ArrayList) result.getTweets();
System.out.println(tweets.size());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.