Quantcast
Channel: Tweetinvi a friendly Twitter C# library
Viewing all articles
Browse latest Browse all 4126

Updated Wiki: Quick Start

$
0
0

Quick Start

Tweetinvi is a C# .NET API developped to simplify the life of developers will to access the Twitter API. It provides an easy access to the Twitter REST API and the Twitter stream API.

Statics and Objects

Tweetinvi provide 2 ways to interacting with the Twitter API.
  • Use a Tweetinvi.* static object to create, read, update or delete an object from Twitter.
  • Use a specific object's method in order to read or update information as well as deleting the object itself
Example to update a Tweet

// Using Static Tweet classvar tweet = Tweet.CreateTweet("Hello");
Tweet.PublishTweet(tweet);

// Using objectvar tweet = Tweet.CreateTweet("Hello");
tweet.Publish();

User

// Get currently logged user - A logged user has unique features notably the ability to update its account settingsvar user = User.GetLoggedUser();

// Get a user from id/namevar user = User.GetUserFromId(USER_ID);
var user = User.GetUserFromScreenName([USER_SCREEN_NAME]);

// Get Friendsvar user = User.GetUserFromId(USER_ID);
var friends = user.GetFriends();

Tweet

// Publish simple tweetvar tweet = Tweet.PublishTweet("Hello!");

// Publish with geo informationvar tweet = Tweet.CreateTweet("Hello guys");
tweet.PublishWithGeo(-54.73, -64.2);

// Retweet
tweet.PublishRetweet();

// Publish in to reply to a tweetvar myReplyTweet = Tweet.CreateTweet("Here is my reply!");
var replyTweet= Tweet.PublishTweetInReplyToTweet(myReplyTweet, tweet);

Message

// Publish a private message to a friend of yoursvar message = Message.PublishMessage("plop", [USER_ID]);

User Feed

// Know everything that happens on an account - Check all the available events from Intellisense!var userStream = Stream.CreateUserStream();
userStream.TweetCreatedByMe += (s, a) => { Console.WriteLine("I posted {0}", a.Tweet.Text); };
userStream.TweetCreatedByFriend += (s, a) => { Console.WriteLine("{0} posted {1}", a.Tweet.Creator.Name, a.Tweet.Text); };
userStream.MessageReceived += (s, a) => { Console.WriteLine("You received the message : {0}", a.Message.Text); };
userStream.StartStream();

Rate Limits

// Access you rate limitsvar rateLimits = RateLimit.GetCurrentCredentialsRateLimits();
Console.WriteLine("You can access your timeline {0} times.", rateLimits.StatusesHomeTimelineLimit.Remaining);

Search

// Search the tweets containing tweetinvivar tweets = Search.SearchTweets("tweetinvi");

Stream

// Access the sample streamvar sampleStream = Stream.CreateSampleStream();
sampleStream.TweetReceived += (sender, args) => { Console.WriteLine(args.Tweet.Text); };
sampleStream.StartStream();

// Access the filtered streamvar filteredStream = Stream.CreateFilteredStream();
filteredStream.AddTrack("ladygaga");
filteredStream.MatchingTweetReceived += (sender, args) => { Console.WriteLine(args.Tweet.Text); };
filteredStream.StartStreamMatchingAllConditions();

Exceptions

To simplify your development and not needing to put try/catch around each of the operation twitter operates, Tweetinvi contains an ExceptionHandler. When an exception occurs, it will retrieve and format all the information for you. Tweetinvi will not raise any exception but the response will be defaulted (e.g. getting a user who does not exist will return null).

var exceptionStatusCode = ExceptionHandler.GetLastException().StatusCode;
var exceptionDescription = ExceptionHandler.GetLastException().TwitterDescription;
var exceptionDetails = ExceptionHandler.GetLastException().TwitterExceptionInfos.First().Message;

Viewing all articles
Browse latest Browse all 4126

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>