使用 Twitter4j 发布推特线程 [英] Posting twitter thread using Twitter4j

查看:30
本文介绍了使用 Twitter4j 发布推特线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试弄清楚如何使用 Twitter4J 使用 Twitter4J 发布推文线程.我猜它会以某种方式使用 StatusUpdate 类,但文档有点稀疏.有什么指点吗?

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?

推荐答案

您应该将 inReplyToStatusId 设置为第一条推文之后的每条推文的最新发布状态 ID.inReplyToStatusId 的默认值为 -1.

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

示例:

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

这篇关于使用 Twitter4j 发布推特线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆