【问题标题】:Twitter4j counting the number of tweets foundTwitter4j 计算找到的推文数量
【发布时间】:2016-03-21 20:52:59
【问题描述】:

这是我查找主题标签的方法:

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 库。我如何计算找到的推文数量?

【问题讨论】:

    标签: java processing twitter4j


    【解决方案1】:

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

    Query query = new Query(searchString);
    QueryResult result = twitter.search(query);
    
    int count = results.getCount();
    System.out.println("tweet count: " + count);
    

    【讨论】:

      【解决方案2】:

      将推文存储在 ArrayList 中并获取 ArrayList 的大小以显示推文的数量。

      ArrayList tweets = (ArrayList) result.getTweets();
      System.out.println(tweets.size());
      

      【讨论】:

      • 我正要评论这个线程说我用类似的 int listSize = tweets.size();无论如何谢谢:)
      猜你喜欢
      • 2011-09-11
      • 2014-12-13
      • 2017-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-01
      相关资源
      最近更新 更多