How To: Twitter search with RadGridView for Silverlight and Twitter REST API

Monday, May 18, 2009 by Vladimir Enchev | Comments 0

I’ve made small demo application on how to search Twitter using Twitter REST API and RadGridView for Silverlight
TwitterSearch

To download Twitter ATOM response you can use simple WebClient:

if (!String.IsNullOrEmpty(TextBox1.Text))
{
    WebClient client = new WebClient();
    client.DownloadStringCompleted += newDownloadStringCompletedEventHandler(client_DownloadStringCompleted);
    if(!client.IsBusy)
        client.DownloadStringAsync(new Uri(String.Format(urlFormat, TextBox1.Text, pageSize, currentPageIndex)));
}

and you can parse the response using XDocument.Parse() method:

XNamespace atomNamespace = "http://www.w3.org/2005/Atom";
RadGridView1.ItemsSource = from item in XDocument.Parse(e.Result).Descendants(atomNamespace + "entry"
                          select new TwitterEntry
                         
{
                               ID = item.Element(atomNamespace + "id").Value,
                               Published = DateTime.Parse(item.Element(atomNamespace + "published").Value),
                               Url = item.Element(atomNamespace + "link").Attribute("href").Value,
                               Title = item.Element(atomNamespace + "title").Value,
                               Content = item.Element(atomNamespace + "content").Value,
                               Updated = DateTime.Parse(item.Element(atomNamespace + "updated").Value),
                               ImageUrl = item.Descendants(atomNamespace + "link").Last().LastAttribute.Value,
                               Author = new TwitterAuthor()
                               {
                                   Name = ((XElement) item.Element(atomNamespace + "author").FirstNode).Value,
                                   Url = ((XElement) item.Element(atomNamespace + "author").LastNode).Value
                               }
                           };

Enjoy!

[Download]

Add comment

  1. Formatting options
       
     
     
     
     
       
  2. (optional, emails won't be shown on public pages)
  3. (optional)