Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Twitter4j api to reply on a tweet?

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
    }
}
like image 963
user1445057 Avatar asked Aug 17 '12 05:08

user1445057


1 Answers

I also had this problem and then i tried having the handler in the text itself.Now it seems to be working.

public static void reply(long inReplyToStatusId,String text,double latitude,double longitude,TwitterFactory factory) throws TwitterException
{   AccessToken accessToken = loadAccessToken();
    Twitter twitter = factory.getInstance();
    twitter.setOAuthConsumer(consumerKey, consumerSecrate);
    twitter.setOAuthAccessToken(accessToken);


    StatusUpdate stat= new StatusUpdate(text);

    stat.setInReplyToStatusId(inReplyToStatusId);


    GeoLocation location= new GeoLocation(latitude, longitude);
    stat.setLocation(location);

    twitter.updateStatus(stat);
 }'

and i called it like

            reply(238912922250792960l, "@praveena_kd testing reply", 12.787, 77.7578, factory);
like image 63
praveena_kd Avatar answered Nov 09 '22 23:11

praveena_kd