Reading a Twitter Feed - It's easy with the Syndication namespace
|
I created a Twitter account yesterday (follow me at julielermanvt) and naturally the first thing I wanted to do was figure out how to consume it. There is lots of API documentation on the Twitter site and I knew what I was after was one of the search API features, e.g., http://search.twitter.com/search.atom?q=to:julielermanvt. I also know how to create an XSD from an XML file (Visual Studio has XML tools that will do this right in the IDE) and how to create a class from an XSD file (still need to use the XSD command line tool). However I was running into a big problem. The search API returns an ATOM or JSON feed, not XML and I was unable to create the class that I wanted to use in my little WPF app. Finally I found this short blog post by .netTiers creator, John Roland: Read an RSS or Atom feed natively with C# (.Net Framework 3.5) that opened up my eyes. There was a new addition to the System.ServiceModel namespace in .NET 3.5 called Syndication. It has handy classes like SyndicationFeed and SyndicationItem and a beautiful method called Load. It has all kinds of Atom and RSS classes as well. With this, I was able to easily grab the tweets I wanted. From SyndicationItem, I could get the entire item or just the pieces I want. The author name (e.g. DevSource editor, JeffCogswell) is the first item in the item.Authors collection. The content of the tweet is contained in item.Title.Text. Here's a little LINQ query I'm using to get just those pieces of info: xmlReader reader = XmlReader.Create Works like a charm and of course, a two minute solution rather than the time I spent futzing with the old method while I was learning my way around the Twitter APIs. I can't help wondering if this new, err new to me, namespace stems from the RSS Toolkit project that ASP.NET team member Dmitry Robsman created in 2006. I even wrote an article about it for aspnetPRO magazine called "Playing in the ASP.NET Sandbox". |


Comments (4)
Thanks Julia!
I just don't have the patience to fiddle around with the Twitter API or the other gazillion APIs out there.
Posted by Thomas Hirsch | June 1, 2009 3:09 PM
And, twitter is going to die soon because who the heck has the time to tell everyone in the world what they are doing at every twist and turn of their life. Sorry. Thats just TOO much information for me to give out to even my own family or friends - let alone someone in Eastern Pakistan in a cave. Thanks but no thanks to ALL of that social networking time sink stuff.
Posted by Mike | June 4, 2009 2:30 PM
And LinkedIn is nothing more than a big Tupperware Party being run by females selling tickets to in-person events where people pay to buy new freinds that might result in some material benefit.
Have you read any LinkedIn Discussions? What a farce. They aren't even discussions but nothing more than weasels trying to write some sleazy subject line to mani=ulate somebody to click and read their bullshit about how to be successful using LinkedIn.
ROFL
LinkedIn: the new STD (Socially Transmitted Disease)
Posted by Clinton Gallagher | June 4, 2009 8:02 PM
Mike
Here's an interesting article about the unexpected value of twitter in Time Magazine:
http://www.time.com/time/business/article/0,8599,1902604,00.html
Julie
Posted by Julie | June 8, 2009 10:39 PM