简体   繁体   中英

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. I can obtain 100 tweets but how do I get the amount of retweets and favorites of each tweet obtained?

        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 (Status status : result.getTweets()) 
        {
            System.out.println("RT "+status.getRetweetCount());
            System.out.println("FAV "+status.getFavoriteCount());
            sb.append(status.getText()+"\n");
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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