Replying to users who tweets your account using Twitter4J

前端 未结 1 1260
情深已故
情深已故 2021-01-17 00:34

I\'m using Twitter4J to send tweets automatically. Basically what I want to do is:

If a user tweets my account, I\'ll reply with \"Hello hello!\" for example. I know

1条回答
  •  生来不讨喜
    2021-01-17 01:21

    Don't use rest api here. Use streaming api (Follow stream). Follow your own handle.

    public void onStatus(Status status) {
      System.out.println("onStatus @" + status.getUser().getScreenName() + " - "+ status.getText());
      System.out.println(status.getInReplyToUserId());
      Twitter tf = new TwitterFactory().getInstance();
      StatusUpdate st = new StatusUpdate("hello");
      st.inReplyToStatusId(status.getId());
      try {
        tf.updateStatus(st);
      } catch (TwitterException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
    

    0 讨论(0)
提交回复
热议问题