Tweets¶
Create, Read, Delete¶
var tweet = await userClient.Tweets.PublishTweetAsync("My first tweet with Tweetinvi!");
var publishedTweet = await client.Tweets.GetTweetAsync(tweet.Id);
await userClient.Tweets.DestroyTweetAsync(tweet);
Tweets are not just text, here are various additional metadata you can add to your tweets.
var fullTweet = await userClient.Tweets.PublishTweetAsync(new PublishTweetParameters("A complex tweet from Tweetinvi")
{
Coordinates = new Coordinates(37.7821120598956, -122.400612831116),
DisplayExactCoordinates = true,
TrimUser = true,
PlaceId = "3e8542a1e9f82870",
PossiblySensitive = true,
});
Extended Tweets¶
Tweets are created by default with
tweet_mode
set toextended
. You can change this in all parameters associated with tweets.
Learn more about extended mode
Retweets¶
// publish a retweet
var retweet = await userClient.Tweets.PublishRetweetAsync(tweet);
// destroy the retweet
await userClient.Tweets.DestroyRetweetAsync(retweet);
// get retweeters
var retweeters = await client.Tweets.GetRetweeterIdsAsync(tweet);
// or
var retweeterIdsIterator = client.Tweets.GetRetweeterIdsIterator(tweet);
Replies¶
// reply to a tweet
var tweet = await userClient.Tweets.GetTweetAsync(1313034609437880320);
var reply = await userClient.Tweets.PublishTweetAsync(new PublishTweetParameters("@" + tweet.CreatedBy + " here is a great reply")
{
InReplyToTweet = tweet
});
// remove the same way as you would delete a tweet
await userClient.Tweets.DestroyTweetAsync(reply);
To send a reply, you must prefix the tweet text with a @username
.
Not doing so will result in the tweet to be sent as a normal tweet and not a reply.
Publish with Media¶
You can attach images, gif and videos that you uploaded to your tweets.
With an image¶
var tweetinviLogoBinary = File.ReadAllBytes("./tweetinvi-logo-purple.png");
var uploadedImage = await userClient.Upload.UploadTweetImageAsync(tweetinviLogoBinary);
var tweetWithImage = await userClient.Tweets.PublishTweetAsync(new PublishTweetParameters("Tweet with an image")
{
Medias = { uploadedImage }
});
With a video¶
var videoBinary = File.ReadAllBytes("./video.mp4");
var uploadedVideo = await userClient.Upload.UploadTweetVideoAsync(videoBinary);
// IMPORTANT: you need to wait for Twitter to process the video
await userClient.Upload.WaitForMediaProcessingToGetAllMetadataAsync(uploadedVideo);
var tweetWithVideo = await userClient.Tweets.PublishTweetAsync(new PublishTweetParameters("tweet with media")
{
Medias = { uploadedVideo }
});
Favorites¶
// favorite
await userClient.Tweets.FavoriteTweetAsync(tweet);
// remove
await userClient.Tweets.UnfavoriteTweetAsync(tweet);
// get user favourites
var favouritedTweets = await userClient.Tweets.GetUserFavoriteTweetsAsync("tweetinviapi");
// or
var favoriteTweetsIterator = userClient.Tweets.GetUserFavoriteTweetsIterator("tweetinviapi");
OEmbed Tweets¶
Twitter can generate HTML for you so that you can display a tweet on your website as it would appear on twitter.
You can generate oembed tweets from Tweetinvi. If you want to learn more please read Twitter documentation.
var oEmbedTweet = await client.Tweets.GetOEmbedTweetAsync(tweet);