2012-08-17 14 views
8

Sto lavorando su Twitter, ho un token di accesso e sto anche ricevendo i tweet ora voglio rispondere su quei tweet come abbiamo fatto nel sito di Twitter per questo sto usando il codice qui sotto ma non è la risposta al tweet ma è aggiornamenti il ​​mio stato si prega di aiutarmi a risolvere questo problema .. GrazieCome utilizzare Twitter4j api per rispondere su un tweet?

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 
    } 
} 
+0

ho risolvere questo problema in stack overflow .. segui questo link http://stackoverflow.com/questions/13134629/in-android-how-directly-post-tweet-to-following-users -of-a-authenticate-user-in Questa risposta Link verifica! spero che questo link possa aiutarti! –

risposta

7

ho anche avuto questo problema e quindi ho provato con il gestore nel testo itself.Now che sembra funzionare.

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

e ho chiamato come

  reply(238912922250792960l, "@praveena_kd testing reply", 12.787, 77.7578, factory); 
0

non ho abbastanza fama di commentare così ho messo questo come una risposta perché ho attaccato su questo per un po 'di tempo. Questo codice, come dichiarato da @praveena_kd, funziona.

String answer = "replying to @" + userNick + ": ..."; 
StatusUpdate statusReply = new StatusUpdate(answer); 
    statusReply.setInReplyToStatusId(statusId); 
    try { 
    twitter.updateStatus(statusReply); 
     } catch (TwitterException ex) { 
     // handle exception 
    } 

Ma bisogna fare attenzione a mettere il @UserScreenName sulla risposta, altrimenti non apparirà sulla timeline del mittente! Dove

String userNick = status.getUser().getScreenName(); 
Problemi correlati