Posting twitter thread using Twitter4j

假如想象 提交于 2019-12-24 21:45:23

问题


I'm trying to figure out how to use Twitter4J to post a tweet thread using Twitter4J. I'm guessing it would be somehow using the StatusUpdate class, but the documentation is a bit sparse. Any pointers?


回答1:


You should set inReplyToStatusId as latest posted status id for every tweet coming after first tweet. Default value for inReplyToStatusId is -1.

Example:

long inReplyToStatusId = -1
int counter = 0
int threadLimit = 5

while (counter < threadLimit){
    StatusUpdate statusUpdate = new StatusUpdate(Integer.toString(counter));
    statusUpdate.setInReplyToStatusId(inReplyToStatusId);

    Status updatedStatus = twitter.updateStatus(statusUpdate);
    inReplyToStatusId = updatedStatus.getId();
    counter++;
}


来源:https://stackoverflow.com/questions/54137712/posting-twitter-thread-using-twitter4j

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!