简体   繁体   English

如何获取Twitter4J中查询的推文的转发和最爱?

[英]How to get retwets and favorites of of the tweets queried in Twitter4J?

I'm using the following code to get the twitter results using twitter4j api of a particular hashtag, say for example #Something. 我正在使用以下代码使用特定主题标签的twitter4j api获取Twitter结果,例如说#Something。 I can obtain 100 tweets but how do I get the amount of retweets and favorites of each tweet obtained? 我可以获得100条推文,但是如何获得所获得的每条推文的转发数和收藏夹?

        Query query = new Query("#SOMETHING");
        query.setCount(100);
        QueryResult result = twitter.search(query);
        for (Status status : result.getTweets()) 
        {
            sb.append(status.getText()+"\n");
        }
        PrintWriter out = new PrintWriter("OutputFile.txt");
        out.print(sb);
        out.close();

How can I get the retweets and favorites of all the tweets obtained above? 如何获得上面获得的所有推文的转发和收藏? Say for example into two separate arrays? 比如说分成两个单独的数组?

Solved: Need to use getRetweetCount() and getFavoriteCount() in the for loop for each tweet. 解决:需要在for循环中为每个tweet使用getRetweetCount()getFavoriteCount()

        for (Status status : result.getTweets()) 
        {
            System.out.println("RT "+status.getRetweetCount());
            System.out.println("FAV "+status.getFavoriteCount());
            sb.append(status.getText()+"\n");
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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