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.
I found the way to do this in https://github.com/klinker24/Talon-for-Twitter and modified it a little
public ArrayList getDiscussion(Status status, Twitter twitter) {
ArrayList replies = new ArrayList<>();
ArrayList all = null;
try {
long id = status.getId();
String screenname = status.getUser().getScreenName();
Query query = new Query("@" + screenname + " since_id:" + id);
System.out.println("query string: " + query.getQuery());
try {
query.setCount(100);
} catch (Throwable e) {
// enlarge buffer error?
query.setCount(30);
}
QueryResult result = twitter.search(query);
System.out.println("result: " + result.getTweets().size());
all = new ArrayList();
do {
System.out.println("do loop repetition");
List tweets = result.getTweets();
for (Status tweet : tweets)
if (tweet.getInReplyToStatusId() == id)
all.add(tweet);
if (all.size() > 0) {
for (int i = all.size() - 1; i >= 0; i--)
replies.add(all.get(i));
all.clear();
}
query = result.nextQuery();
if (query != null)
result = twitter.search(query);
} while (query != null);
} catch (Exception e) {
e.printStackTrace();
} catch (OutOfMemoryError e) {
e.printStackTrace();
}
return replies;
}