Click here to Skip to main content
Click here to Skip to main content
Technical Blog

Tagged as

How to Read Twitter Feeds With LINQ to XML

, 2 Apr 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
Twitter feeds are provided in RSS XML format. This makes it very easy for us to parse out the information we want from a feed using LINQ to XML. For example, if we want to grab the message and date of each Twitter entry, we could use something like this: public class Twitter {     public str

Twitter feeds are provided in RSS XML format. This makes it very easy for us to parse out the information we want from a feed using LINQ to XML. For example, if we want to grab the message and date of each Twitter entry, we could use something like this:

public class Twitter
{
    public string Message { get; set; }
    public DateTime PubDate { get; set; }

    public static List<Twitter> Parse(string User)
    {
        var rv = new List<Twitter>();
        var url = "http://twitter.com/statuses/user_timeline/" + User + ".rss";
 
        var element = XElement.Load(url);
        foreach (var node in element.Element("channel").Elements("item"))
        {
            var twit = new Twitter();
            var message = node.Element("description").Value;

            //remove username information
            twit.Message = message.Replace(User + ": ", string.Empty);
            twit.PubDate = DateTime.Parse(node.Element("pubDate").Value);
            rv.Add(twit);
        }

        return rv;
    }
}

You can get the twitter feeds by using the following:

		var fromTwitter = Twitter.Parse("Merlin981");

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

merlin981
Software Developer (Senior)
United States United States
Winner - Best Mobile App - AT&T Developer Summit, Las Vegas, 2013
 
My personal resume can be found at: http://www.philippiercedeveloper.com
 
My game portfolio can be found at: http://www.rocketgamesmobile.com
 
About Philip Pierce:
 
I am a software developer with twenty years experience in game development, mobile, web, desktop, server, and database. My extensive background highlights an expertise in rapid application development using the latest Microsoft, Mobile, and Game Development technologies, along with the ability to create AI for games and business software, redesign existing software, develop multi-threaded software, and create client/server applications.

Comments and Discussions

 
QuestionSeems not to work anymore PinmemberCodeBetweenTheLines30-Nov-12 9:00 
GeneralMy vote of 5 Pinmemberversion_2.029-Sep-11 21:31 
GeneralIt's not reading Pinmembercyberion8418-May-10 15:33 
GeneralRe: It's not reading PinmemberTolupoint4-Sep-12 7:30 
Generalhi Pinmembermbaocha25-Aug-09 11:42 
GeneralOr more concisely ... using a few more LINQ features ... PinmemberHightechRider2-Apr-09 9:35 
GeneralRe: Or more concisely ... using a few more LINQ features ... PinmemberTolupoint4-Sep-12 8:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.141029.1 | Last Updated 2 Apr 2009
Article Copyright 2009 by merlin981
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid