[英]Twitter4j reply to tweet not working
I'm trying to reply to a tweet (that i post 10 seconds before) using twitter4j but it is only posting it to the timeline and not as a reply. 我正在尝试使用twitter4j回复一条推文(我在10秒钟前发布),但它仅将其发布到时间轴而不是作为回复。
post = mainTwitter.updateStatus(...); //1st twitter account
StatusUpdate reply = new StatusUpdate(...);
try {
reply.setInReplyToStatusId(post.getId());
contextTwitter.updateStatus(reply); //2nd twitter account
} catch (TwitterException e) {
System.err.println("Couldn't post context");
e.printStackTrace();
}
The id is not -1, it is the right long value. id不是-1,它是正确的long值。 No exception thrown.
没有引发异常。
You can use the following code to make your snippet working 您可以使用以下代码使代码段正常工作
public void init() {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey(TWITTER_CONSUMER_KEY)
.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET)
.setOAuthAccessToken(TWITTER_ACCESS_TOKEN)
.setOAuthAccessTokenSecret(TWITTER_ACCESS_SECRET);
TwitterFactory tf = new TwitterFactory(cb.build());
twitter = tf.getInstance();
}
/***
*
* @param tweetId : tweet Id
* @param messgae : Reply message
* @return
* @throws TwitterException
*/
public String reply(String tweetId, String messgae ) throws TwitterException {
Status status = twitter.showStatus(Long.parseLong(tweetId));
Status reply = twitter.updateStatus(new StatusUpdate(" @" + status.getUser().getScreenName() + " "+ messgae).inReplyToStatusId(status.getId()));
return Long.toString(reply.getId());
}
Usage : 用法:
reply("930497966443454464", " Hello Eva")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.