首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Twitter4j统计发现的tweet数量

Twitter4j统计发现的tweet数量
EN

Stack Overflow用户
提问于 2016-03-21 00:33:12
回答 2查看 1.1K关注 0票数 2

下面是我查找hashtag的方法:

代码语言:javascript
复制
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库。我该怎么统计发现的推文数量?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-03-21 00:44:14

将这些tweet存储在ArrayList中,并获取ArrayList的大小以显示tweet的数量。

代码语言:javascript
复制
ArrayList tweets = (ArrayList) result.getTweets();
System.out.println(tweets.size());
票数 0
EN

Stack Overflow用户

发布于 2016-03-21 12:52:59

您还可以使用QueryResult.getCount()函数。

代码语言:javascript
复制
Query query = new Query(searchString);
QueryResult result = twitter.search(query);

int count = results.getCount();
System.out.println("tweet count: " + count);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36121419

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档