tweetsharp: A .NET Twitter Library

I’ve been diving into the world of .NET development a little more these days and decided to further my leaning some by playing around with the Twitter API. In looking around the net I came across a cool Twitter library for .NET named tweetsharp. It appears to be a fairly new project, so the documentation is a bit lackluster at the moment. I put together a quick page that calls one of the tweetsharp methods to return a list of tweets from my friend’s timeline.

For those of you new to .NET, once you download the library and uncompress the files you will see two .DLL files. Copy these over to your Bin directory of your website. This will allow you to import this library and use it throughout your website or application. One file contains the base tweetsharp library and the other is a helper library for JSON. The data that is returned from the tweetsharp library can be returned in many formats, so if you plan on using the JSON data you will need to include the helper library.

Below is the code for the code behind page, which contains the guts of the logic. Notice the import calls to the tweetsharp files in the top half of the code. The rest of the code is fairly short. I call the tweetsharp library and set up my return data variables. I then bind the data to a ListView control.

<code lang="csharp[lines]">using System;<br></br>
using System.Collections.Generic;<br></br>
using System.Linq;<br></br>
using System.Web;<br></br>
using System.Web.UI;<br></br>
using System.Web.UI.WebControls;<br></br>
using System.Threading;<br></br>
using Dimebrain.TweetSharp.Fluent;<br></br>
using System.Xml;<br></br>
using System.Xml.Linq;<br></br>
using Dimebrain.TweetSharp.Model;<br></br>
using Dimebrain.TweetSharp.Extensions;

public partial class test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var twitter = FluentTwitter.CreateRequest()
.AuthenticateAs("YOURUSERNAME", "YOURPASSWORD")
.Statuses().OnFriendsTimeline().AsXml();

var response = twitter.Request();

var statuses = response.AsStatuses();

ListView1.DataSource = statuses;
ListView1.DataBind();

Context.Trace.Write("OP", response.ToString());
}
}

The next part of the code is main ASPX file, and contains my ListView control that I have bound the data to. I set up my item template and then output my data.

<code lang="csharp[lines]">





" />

This code produces the output below. Yes, it’s very vanilla output, but we can clean up our display later.

tweetsharp

Using the tweetsharp library makes this code super simple, as all the underlying API calls are taken care of by the library. I plan on updating this some more and I’ll provide some more examples.

Comments

comments powered by Disqus