tweetsharp: A .NET Twitter Library

Mar

25

by Mike Fleming at 8:03 pm (3 Comments) .NET, Twitter


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.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading;
using Dimebrain.TweetSharp.Fluent;
using System.Xml;
using System.Xml.Linq;
using Dimebrain.TweetSharp.Model;
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.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" Trace="true" %>









" />
<%#Eval("User.ScreenName")%>
<%#Eval("Text")%>
<%#Eval("CreatedDate")%>



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.


Categories .NET, Twitter | Tags:

3 Responses to “tweetsharp: A .NET Twitter Library”

  1. Daniel

    March 26, 2009
    8:42 am

    Hi Mike,

    Thanks for doing this write up on tweet#! We’re trying to put together an instructional site over at http://tweetsharp.com but we’re not there, so posts like these really help.

    • Mike Fleming

      March 27, 2009
      7:41 am

      No problem. I plan on posting some more about using the library when I have a chance to play around with it a little more.

  2. Osama

    March 3, 2010
    8:03 am

    How can I query for tweets that contain specific keywords?

    I have tried this:
    var twitter = FluentTwitter.CreateRequest()
    .AuthenticateAs(“userid”, “pwd”)
    .Search().Query()
    .Containing(“crm+OR+sakonent”)
    .AsJson();

    it doesnt work for me

    Any help would be appreciated.

    Thanks

Leave a Reply or Return to Top