Question

I need to stream all public tweets which contain a certain hashtag AND replies to a certain account (which I own) and store them in a database. However, I can't get Twitter4j to do this for me.

Is there something I'm missing? I've only been able to stream my timeline.

Was it helpful?

Solution

You cannot specify criteria like "replies to a certain account" with filter stream. However, it is possible to detect if a tweet is a reply to a certain account by using Status#getUserMentionEntites(). The code will be like this:

public void onStatus(Status status){
  for(UserMentionEntity mention : status.getUserMentionEntities()){
    if(mention.getScreenName().equals("yusuke")){
      // do whatever you want
      break;
    }
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top