Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
549 views
in Technique[技术] by (71.8m points)

java - Twitter4j: Get list of replies for a certain tweet

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

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

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...