-
Notifications
You must be signed in to change notification settings - Fork 221
Tweets before Tweetinvi 0.9.9.x
Tweets are 140 characters text messages that can contain various information entities like HashTags, Locations, Images, Videos, URLs.
PLEASE NOTE THAT TWEET PUBLICATION WILL BE IMPROVED IN VERSION 0.9.9.0
- Publish Tweets
- Publish Tweets with media
- Tweet Length
- Publish a Retweet
- Delete Tweets
- Favorite Tweets
- Oembeded Tweets
Please note that instead of a <tweet_identifier> you can use either a (long) tweet_id, an ITweet or an ITweetDTO.
Lets start by publishing a simple tweet...
// *** In a single call ***
var firstTweet = Tweet.PublishTweet("I love Tweetinvi!");
// *** In 2 steps ***
var firstTweet = Tweet.CreateTweet("I love Tweetinvi!");
// If the Publish method succeed the tweet is hydrated with the data return by Twitter.
var success = firstTweet.Publish();
Now let's publish a reply to the first tweet.
var reply = Tweet.CreateTweet("Tweetinvi loves you back!");
// If the operation is a success, the reply object is updated
var success = firstTweet.PublishReply(reply);
If you want to add some geo localization information use the appropriate method.
var tweet = Tweet.CreateTweet(text);
var coordinates = new Coordinates(longitude, latitude);
var success = tweet.PublishWithGeo(coordinates);
Twitter allows developer to send images and videos within Tweets. Tweets have an AddMedia
method that allow developers to simply add a byte[] as a media of the tweet.
byte[] file1 = File.ReadAllBytes(filePath);
byte[] file2 = File.ReadAllBytes(filePath);
var tweet = Tweet.CreateTweet("hello");
tweet.AddMedia(file1);
tweet.AddMedia(file2);
var success = tweet.Publish();
Before publishing a Tweet you should ensure that the size of the Tweet contains less than 140 characters. Twitter has a very specific mechanism to calculate the size of a Tweet based on the hashtags, urls, medias...
To simplify your life, Tweetinvi has implemented an extension method to the String class as well as a Length
property to the ITweet interface and you can
// From a Tweet
var tweet = Tweet.CreateTweet("I love https://github.com/linvi/tweetinvi");
var twitterLength = tweet.Length;
// From a string (the extension namespace is 'Tweetinvi.Core.Extensions')
var twitterLength = "I love https://github.com/linvi/tweetinvi".TweetLength();
var retweet = Tweet.PublishRetweet(<tweet_identifier>);
var success = Tweet.DestroyTweet(<tweet_identifier>);
var success = Tweet.FavoriteTweet(<tweet_identifier>);
var oembedTweet = Tweet.GenerateOEmbedTweet(<tweet_identifier>);