Tweets and dynamic content decided to become friends

by: Peter Sunna

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:

Screenshot of Latest Tweets dynamic content module in action

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
    • Design and art

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


Comments

  1. I'm one of those three people, yay! :)
  2. Hi Peter! I created the exact same module on Monday (using your code from the UKTop40PageProvider). I was about to upload it to EPiCode, but you beat me to it ;-)
  3. That is actually both cool and useful!
  4. And as always a cool thing is even cooler once its put into a real context. See screenshot where Twitter is a part of a news article in Relate+ (togheter with forum and clubs and videos - its in norwegian but you get the general ide). http://labs.episerver.com/Global/Blog%20pictures/eksempel_twitter_nyheter.png.
  5. Cool yes, useful - well... but it does not have to be :D
  6. Nice going Peter!
  7. Ted: 03.17?? Give me your sleeping pills, you don't need them. Mari: I published this post 02.12. Time to market is important...I'm sure your version is prettier though. Steve: It's useful, just listen to your fellow Norwegians :)
Post a comment    
User verification Image for user verification  
Peter Sunna

About me

Technical sales engineer at EPiServer Stockholm. Web standards, accessibility and beautiful code makes me smile (sometimes at least).

Syndications


Archive


Tag cloud

EPiTrace logger