8

我在推特上工作,我有访问令牌,现在我也收到了推文我想像我们在推特网站上所做的那样回复推文状态请帮我解决这个问题谢谢..

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
    }
}
4

3 回答 3

8

我也遇到了这个问题,然后我尝试在文本本身中使用处理程序。现在它似乎正在工作。

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

我称它为

            reply(238912922250792960l, "@praveena_kd testing reply", 12.787, 77.7578, factory);
于 2012-08-24T08:23:47.400 回答
0

我没有足够的声誉来发表评论,所以我把它作为答案,因为我坚持了一段时间。@praveena_kd 所述的此代码有效。

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

但是您必须注意将@UserScreenName放在回复中,否则它不会出现在发件人时间线上!在哪里

String userNick = status.getUser().getScreenName();
于 2016-02-20T12:30:03.057 回答
0

您需要将用户名添加到响应中,在Twitter4j中,这称为screenName

例如:

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

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

于 2021-05-22T16:07:20.380 回答