Subscribe

Close

Thank you for visiting!

Please consider subscribing to the RSS feed or following me on Twitter.

Twitter module in ASP.NET for download

If you've been looking for an ASP.NET Twitter module, look no further. I've coded a C# module in order to consume a given Twitter feed. Download the Twitter module for easy use in your own project.

How to use

You can either show the latest Twitter message or any given number of Twitter messages with this module - all you have to do is to point out a Twitter username and the number of messages to show.

Here's a code example on how you can show 5 Twitter messages in a Repeater.

Code-behind:

string userName = "dileno";

List<TwitterFeed> messages = TwitterFeed.Fetch(userName, 5);

if (messages.Count>0)
{
rptTwitterMessages.DataSource = messages;
rptTwitterMessages.DataBind();
}

Repeater in code-front (aspx/ascx):

<asp:Repeater ID="rptTwitterMessages" runat="server">
<HeaderTemplate><ul></HeaderTemplate>
<FooterTemplate></ul></FooterTemplate>
<ItemTemplate><li><%#((TwitterFeed)Container.DataItem).Message %> (<a href="<%#((TwitterFeed)Container.DataItem).Link %>"><%#((TwitterFeed)Container.DataItem).PubDate %></a>)</li></ItemTemplate>
</asp:Repeater>

Download the Twitter module

You can download the C# module with complete source code and code examples:

Download Twitter module (zip, 16 kB)

Short instructions for implementation

  • Drop the TwitterFeed.cs file into your project.
  • Use the code in Default.aspx.cs to customize the Twitter messages.
  • Update your appSettings.Config with the key TwitterFeedUrl, which you find in this project's appSettings.Config file.

Comments

Great stuff Martin!

Does the module cache the latest tweets or does it fetch them for each request?

Thanks!

Actually, no cache is involved in this one. Maybe it'll come as an option in the future :)

I thought it was better to always fetch new items, given how often some Twitter users update their status.

Great stuff! :)

Twitter does have a limit of 150 requests per hour per user account. So after 150 requests have been made, no Tweets would be fetched. :(

So caching would be a great addition. Then you can hook up to the "remove from cache"-event (I don't remember exactly what it's called) and check if less than 150 requests have been made for the current time interval (one hour).

If so, then it is safe to remove the tweets from the cache, if not, then don't remove the cache until it is safe to make new Twitter requests. :)

Keep up the good work!

Daniel, thanks for your contribution!

I will definitely build a cache mechanism into this module, specially since I've seen the API calls go beyond the limit, thus not showing latest tweets.

I have changed the username from dileno to my username and recompiled, but it still fetches the tweets from dileno.

Am I missing something?

Thank you soooooooooooo much.
this is a simplest api i serched for twitter feeds.

You are great!

thanks
Annam

Hi this is realy ggod atricle.

Butmy requirement is like this

once i login to my web application there is twiter area in that i have to display lates tweets from my twitter account. i have to enter login id and password then i should get all the tweets which posted in my twitter acccount( those who i follow) similer to tweets in twitter home page how can i achive this can please help me

i can reach by id -sreenathbhatta@yahoo.com

Thanks in Advance
Sreenatha D Bhat

To the top