Tweets and dynamic content decided to become friends
I just made a really simple dynamic content module that I thought I share with you. If you’re one of the three persons who have actually read my article EPiServer Loves UK Top 40 you know that it includes a Twitter search for the latest tweets regarding an artist. With the use of a Visual Basic design pattern called copy & paste I have now turned that code into a dynamic content module. It works in the way that the editor specifies what to search for, for example #episerver to find the latest tweets containing the episerver hashtag, and the number of hits to show. The result will look something like this when used inside a paragraph about social notworking:

Twitter still hasn’t got a search api were you can do more relevant searches, for example sorting the tweets by number of followers or number of retweets. However, this will do the trick to get the latest updates on a particular subject. I really recommend using hashtags though since this will hopefully give more relevant information regarding for example a product.
Looking at the code you will see that I’ve used Linq to parse the search result which is delivered as an atom feed from Twitter. To improve performance and be kind against the Twitter servers I’ve added caching were the cache key is a composite of the search term and max count. By default it’s set to timeout after 10 minutes. The screenshot above also reveals the time I’ve spent to get the dates “just right”.
The code resides in four different files:
- LatestTweets.cs
- Handles the dynamic content state and properties in edit mode
- LatestTweetsControl.ascx
- Renders the tweets using a repeater
- LatestTweetsControl.ascx.cs
- Fetches feed, handles cache and includes Css
- LatestTweets.css
As usual you’ll have to register the dynamic content control in web.config. See the readme.txt file within the zip for details.
If you like to try it out, download the zip containing the Latest Tweets dynamic content module and start playing.
18 March 2009