-
Notifications
You must be signed in to change notification settings - Fork 216
Tweet 0.9.9.x
Tweets are 140 characters text messages that can contain various information entities like HashTags, Locations, Images, Videos, URLs.
- 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 tweet = Tweet.PublishTweet("I love Tweetinvi!");
// *** Create a variable that you can pass through your functions ***
var publishParameter = new PublishTweetParameters("I love tweetinvi!", new PublishTweetOptionalParameters());
var tweet = Tweet.PublishTweet(publishParameter);
When publishing a tweet you can set up various optional parameters. The PublishTweetOptionalParameters
will let you configure these parameters.
-
Reply
specifies which tweet you want to reply to. -
Geo
specifies geographic information for the tweet. -
Media
specifies which media you want to add to the tweet. -
Sensitive
specifies whether media published with the tweet could be sensitive for other users. -
Other parameters
...
In the sections below you will be provided with examples
InReplyToTweet
/InReplyToTweetId
specify which existing tweet you want to reply to.
var tweetToReplyTo = Tweet.PublishTweet("Tweetinvi loves its geeky developers!");
var tweet = Tweet.PublishTweet("We love you back!", new PublishTweetOptionalParameters
{
InReplyToTweet = tweetToReplyTo,
// OR
InReplyToTweetId = tweetToReplyTo.Id
});
PlaceId
specifies a place from where you've been publishing the tweet.
var sanFranciscoPlaceId = "5a110d312052166f";
var tweet = Tweet.PublishTweet("Hello San Fransisco!" + Guid.NewGuid(), new PublishTweetOptionalParameters
{
PlaceId = sanFranciscoPlaceId
});
Coordinates
specifies a more precise location from where the Tweet has been published.
var sanFranciscoCoordinates = new Coordinates(-122.40062, 37.78217);
var tweet = Tweet.PublishTweet("Hello San Fransisco!" + Guid.NewGuid(), new PublishTweetOptionalParameters
{
Coordinates = sanFranciscoCoordinates
});
-
DisplayExactCoordinates
will let followers see a pin for the exact location where the tweet has been published.
Media
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>);