Let's first define what Twitter is.
Twitter is a free internet service that is a
microblogging system that allows users to send short text notes (up to 140 characters) using a web interface,
SMS ,
instant messaging services, or third-party client programs (
http://ru.wikipedia.org ).
The second question is, why is it needed at all? Just chatting with friends? This is an option, but still there are more convenient messaging services. Most likely for publishing and tracking news (both personal and public).
')
So, if you have a certain online store, or a company site where you publish news, then you can create a twitter account in order to duplicate there information about the release of new publications on the site (both news and the arrival of new products) , or you can fasten to your blog the ability to publish on Twitter information about the arrival of new topics (there are ready services like
http://twittsync.com/ , working on Microsoft Azure). You can also use Twitter “for other purposes” - you can create some empty account that will publish, for example, the state of your computer, via Direct Message to your account or just to your homepage - one example: your provider requires money for a white IP address, otherwise it assigns you an address dynamically, and every 24 hours you are chopped off (this is for those who use routers) and you want to find out what IP address you have at any time (for example, from work) log into your home computer remotely.
The next question is, is it difficult to do?
Easy! You can go a little more complicated way and learn TwitterAPI yourself, then you will not need to depend on anything, first you need to use the article -
Michael C. Kennedy - Building a Twitter Application in .NET , the easier way is to use a ready-made
LINQ to solution
Twitter (I'll use it).
So let's start with the simplest example. Create a console application with the following code:
using System; <br> using System.Linq; <br> using LinqToTwitter; <br><br> namespace TwitterIntegration <br>{ <br> internal class Program <br> { <br> private static void Main() <br> { <br> // , <br> UsernamePasswordAuthorization auth = new UsernamePasswordAuthorization <br> { <br> UserName = "UserName" , <br> Password = "Password" <br> }; <br><br> // twitter <br> TwitterContext twitterCtx = new TwitterContext(auth); <br> // <br> auth.SignOn(); <br><br> // twit', ( ) <br> var publicTweets = <br> from tweet in twitterCtx.Status <br> where tweet.Type == StatusType.Friends <br> select tweet; <br><br> // <br> publicTweets.ToList().ForEach( <br> tweet => Console .WriteLine( <br> "User Name: {0}, Tweet: {1}" , tweet.User.Name, tweet.Text)); <br><br><br> auth.SignOff(); <br><br> Console .WriteLine( "Press any key to end this demo." ); <br> Console .ReadKey(); <br> } <br> } <br>} <br><br> * This source code was highlighted with Source Code Highlighter .
Isn't it all very simple (don't forget to replace the user and password in your case). And
TwitterContext can just as easily work with
http://jtweeter.com and
http://identi.ca (the same sites for microblogging).
But let's go back to our script. We decided to publish our IP address. The first question is how to find out the IP address of our computer, for this you can refer to the article
Get the IP address in a Windows application on
geekpedia -
let 's use the last method (which uses the
http://www.geekpedia.com/ip.php service), so as this method also takes into account the fact that your computer can be sent through a router (like mine):
private static string GetIpAddress() <br>{ <br> WebClient myWebClient = new WebClient(); <br> Stream myStream = myWebClient.OpenRead( "http://www.geekpedia.com/ip.php" ); <br> StreamReader myStreamReader = new StreamReader(myStream); <br> return myStreamReader.ReadToEnd(); <br>} <br><br> * This source code was highlighted with Source Code Highlighter .
This method uses classes from the System.IO and System.Net named spaces (do not forget to connect using). Create a new project -
Windows Service , add to it immediately information about the installation (
How to: Add Installers to Your Service Application ). We will use the
Timer class (from System.Timers), which will call the method every 60 minutes, which will publish the IP address:
private static void TwittIpAddress( object sender, ElapsedEventArgs e) <br>{ <br> UsernamePasswordAuthorization auth = new UsernamePasswordAuthorization <br> { <br> UserName = "UserName" , <br> Password = "Password" <br> }; <br><br> // twitter <br> TwitterContext twitterCtx = new TwitterContext(auth); <br> // <br> auth.SignOn(); <br><br> string message = string .Format( "My IP Address is: {0}" , GetIpAddress()); <br><br> // tweet <br> twitterCtx.UpdateStatus(message); <br><br> // <br> twitterCtx.NewDirectMessage( "ToUserName" , message); <br><br> auth.SignOff(); <br>} <br><br> * This source code was highlighted with Source Code Highlighter .
In this method, we first update the account status UserName, as well as send a message to the user ToUserName. To install the Windows Service, use the
InstallUtil utility.
As you can see, integrating your application or website with trendy Twitter is easy. Moreover, this way you can increase your chances in all sorts of contests, such as
drawing invitations to Google office (and there are many similar draws). Sample application can be downloaded below.

