twitter-api-v2
twitter-api-v2 copied to clipboard
Consider to add method to create a thread tweet
Have you considered adding an additional public API method to do this automatically with a long String where if it exceeds the character limit imposed by Twitter then it'll convert it into a thread and add a reply to the original tweet?
From there you could do add additional configuration for creating threads such as:
- Having a thread tweet total e.g (1/5)
- Option to have only the tweet count on the opening tweet
- Having a number prefix before the content of each tweet like the way is done in the thread I linked
- Or perhaps having the number as a suffix at the end of the tweet e.g. (1)
Originally posted by @MarkOSullivan94 in https://github.com/twitter-dart/twitter-api-v2/discussions/400#discussioncomment-3565749
import 'package:twitter_api_v2/twitter_api_v2.dart' as v2;
Future<void> main() async {
final twitter = v2.TwitterApi(
bearerToken: 'YOUR_TOKEN_HERE',
);
try {
final rootTweet = await twitter.tweetsService.createTweet(
text: 'Test tweet via #twitter_api_v2',
);
final contents = [
'content1',
'content2',
'content3',
];
var parentTweetId = rootTweet.data.id;
for (final content in contents) {
final threadTweet = await twitter.tweetsService.createTweet(
text: content,
reply: v2.TweetReplyParam(
inReplyToTweetId: parentTweetId,
),
);
parentTweetId = threadTweet.data.id;
}
} on v2.TwitterException catch (e) {
print(e);
}
}