(1) Get a copy of the Twitterizer Library
First, you’ll need to get a copy of the http://code.google.com/p/twitterizer/. The download is pretty small and contains only
the application library (DLL) you need. Create a new website in ASP.NET
and extract the twitterizer library to the /bin/ folder so that you can
use it. Once you have it placed in your /bin/ folder, add a “using”
reference to the library in the header of your page.
using Twitterizer.Framework;
(2) Create a “Twitter” object and Retrieve Your Status
Updates.
The library contains a few different objects that you can create. A
“Twitter” object is the most generic object that you can create.
Creating an instance of this object using your username and password
gives you all the functionality you would normally have in Twitter, but
instead of using the Twitter web interface, you’re using C# or Visual
Basic. First, we’ll need to instantiate the object, and then get a
collection of status updates from your account.
Twitter thisUser = new Twitter(“UserNameHere”, “PasswordHere”);
TwitterStatusCollection thisCollection = thisUser.Status.UserTimeline();
(3) Loop Through Your Status Updates and Generate Some HTML
The “TwitterStatusCollection” object type is a list of
“TwitterStatus” objects, so you can use a foreach loop and go through
your most recent status updates. You’ll notice in the code below that I
also do some basic work with the time of the status update to generate a
hyperlink to the page of the status, similar to what Twitter does.
string TwitterCode = “”;
foreach (TwitterStatus thisStatus in thisCollection)
{
TimeSpan thisSpan = new TimeSpan();
thisSpan = DateTime.Now.Subtract(thisStatus.Created);
string TimeBetween = “”;
if (thisSpan.Days > 0) { TimeBetween = thisSpan.Days.ToString() + ”
days ago”; }
else if (thisSpan.Hours > 0) { TimeBetween = thisSpan.Days.ToString()
+ ” hours ago”;}
else if (thisSpan.Minutes > 0) { TimeBetween =
thisSpan.Days.ToString() + ” minutes ago”;}
else if (thisSpan.Seconds > 0) { TimeBetween =
thisSpan.Days.ToString() + ” seconds ago”;}
TwitterCode += “<div class=’TwitterStatus’>” + thisStatus.Text +
” <a href=’http://twitter.com/” + thisStatus.TwitterUser.UserName +
“/status/” + thisStatus.ID + “‘>” + TimeBetween +
“</a></div>”;
}
(4) Display Your Tweets
You now have a string with your most recent twitter status updates
that you can display on the page using a simple Response.Write() or you
can display it in a label. You can see a variation of this code running
on the http://www.360webcms.com/addons/twitter/.
You can also download a copy of my http://www.adventuresindevelopment.com/wp-content/uploads/2009/06/twitter.zip.
Hope this will help you.