How to use Twitter4j api to reply on a tweet?

Viewed 6113

I am working on twitter, I have access token and I am also getting the tweets now I want to reply on that tweets like we did in Twitter website for this I am using the below code but it's not reply to the tweet but it updates my status please help me to solve this issue Thanks..

public void tweetReply() {
    try {
        // System.out.println("Post Id= " + itemsObj.postId);
        AccessToken a = new AccessToken(twittertokens[0], twittertokens[1]);
        Twitter twitter = new TwitterFactory().getInstance();

        twitter = new TwitterFactory().getInstance();
        twitter.setOAuthConsumer(Constants.CONSUMER_KEY, Constants.CONSUMER_SECRET);
        twitter.setOAuthAccessToken(a);
        Long id = new Long("236178766597087234");
        twitter.updateStatus(new StatusUpdate("@lalitrajput024  this is to test For reply option ").inReplyToStatusId(id));

    } catch (Exception e) {
        // TODO: handle exception
    }
}
3 Answers

You need to add the username to the response, in Twitter4j this is known as the screenName

For example:

String username = status.getUser().getScreenName();

String answer = "@".concat(username).concat(" Here goes your response ");

Related