回复使用Twitter4J推文您的帐户的用户 [英] Replying to users who tweets your account using Twitter4J

查看:199
本文介绍了回复使用Twitter4J推文您的帐户的用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Twitter4J自动发送推文。基本上我想做的是:

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

如果用户推特我的帐户,我会回答你好你好!例如。我知道如何使用Twitter4J进行推文,但只是不知道如何回复给我发推文的用户。

If a user tweets my account, I'll reply with "Hello hello!" for example. I know how to tweet using the Twitter4J but just don't know how to reply to users that tweet me.

这就是我做正常推文的方式:

This is the way I'd just do a normal tweet:

// The factory instance is re-useable and thread safe.
Twitter twitter1 = TwitterFactory.getSingleton();
Status status = twitter1.updateStatus("Hello Hello");
System.out.println("Successfully updated the status to [" + status.getText() + "].");

我想我需要这样做:
1.请求最后一条推文
2 。如果newTweet.id!= oldTweet.id则表示您有新消息,否则跳转到第4步
3.回复
4.循环1

I think I need to do: 1. Request last tweet 2. If newTweet.id != oldTweet.id then it means you have a new message else jump to step 4 3. Reply 4. Loop 1

推荐答案

不要在这里使用rest api。使用流式api(关注流)。按照你自己的句柄。

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();
  }
}

这篇关于回复使用Twitter4J推文您的帐户的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆