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.
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
You can use InReplyToStatusId
field value using Status.getInReplyToStatusId()
Use the code code below recursively to get all replies or conversations of a tweet using API v1.1:
Status replyStatus = twitter.showStatus(status.getInReplyToStatusId());
System.out.println(replyStatus.getText())
Using this I could pull Tweets with all of their replies.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With