Twitter RSS Feed Reader in MVC 4

In this article you will learn how to setup the Twitter RSS Feed Reader in MVC 4. I'm using the same technique I used in my last article to read the Facebook feeds. Let's look at the image that we will be creating using the given code.

At the very first, setup the model like this:

    public class TwitterRSS


        public string Title { getset; }

        public string Link { getset; }

        public string PubDate { getset; }


    public class TwitterRssReader


        public static IEnumerable<TwitterRSS> GetFeed()


            var client = new WebClient();

            client.Headers.Add("user-agent""Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");

            var xmlData = client.DownloadString("");

            XDocument xml = XDocument.Parse(xmlData);

            var TwitterUpdates = (from story in xml.Descendants("item")

                                select new TwitterRSS


                                    Title = ((string)story.Element("title")),

                                    Link = ((string)story.Element("link")),

                                    PubDate = ((string)story.Element("pubDate"))


            return TwitterUpdates;



You need to change the above download string URL or just replace your twitter handler name or screen name.

Now, let me show you the twitter RSS page that we tried to target in the above code:

Now, setup the controller like this:

        public ActionResult Index()


            ViewBag.TwitterFeed = RSS_Reader.Models.TwitterRssReader.GetFeed();

            return View();


Next, use the following view page:




        <h3>Twitter Updates</h3>



@foreach (var item in ViewBag.TwitterFeed)




        @item.Title <a href="@item.Link" target="_blank"> more </a> on @Convert.ToDateTime(item.PubDate)





Now you are all set, run the application.

Hope this helps. Thanks.


Build smarter apps with Machine Learning, Bots, Cognitive Services - Start free.

Start Learning Now