Reputation: 27
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 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() + "].");
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
Upvotes: 0
Views: 1376
Reputation: 1000
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();
}
}
Upvotes: 1