Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Is it possible to get a list of tweets that reply to a tweet (or to its replies) using twitter4j? The twitter website and Android app have this feature.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
532 views
Welcome To Ask or Share your Answers For Others

1 Answer

Here's a code I'm using in welshare

The first part gets all the tweets that twitter is displaying below the tweet, when it is opened. The rest takes care of conversations, in case the tweet is a reply to some other tweet.

RelatedResults results = t.getRelatedResults(tweetId);
List<Status> conversations = results.getTweetsWithConversation();
/////////
Status originalStatus = t.showStatus(tweetId);
if (conversations.isEmpty()) {
    conversations = results.getTweetsWithReply();
}

if (conversations.isEmpty()) {
    conversations = new ArrayList<Status>();
    Status status = originalStatus;
    while (status.getInReplyToStatusId() > 0) {
        status = t.showStatus(status.getInReplyToStatusId());
        conversations.add(status);
    }
}
// show the current message in the conversation, if there's such
if (!conversations.isEmpty()) {
    conversations.add(originalStatus);
}

EDIT: This wont work anymore as Twitter API v 1 is now not in use


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...