Don Hosek
Don Hosek

Reputation: 1021

Posting twitter thread using Twitter4j

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?

Upvotes: 0

Views: 232

Answers (1)

kadir
kadir

Reputation: 599

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

Upvotes: 2

Related Questions