RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Programming Twittering with Visual Basic : Page 3

Discover how easy it is to call the Twitter API from your .NET applications.


Building a Simple Client

Now I'll create a simple client that displays statuses on-screen. This application has two parts: a simple WPF-based ListBox to format status objects, and a class that abstracts the complexities of Twitter's XML or JSON formats.

Listing 2 is a domain object representing a status update. It has three properties: the message text, the poster's screen name, and the URL to the poster's image.

Here's the XAML for a formatted ListBox capable of showing the status updates pulled from the URL you looked at in the beginning of this article.

   <ListBox IsSynchronizedWithCurrentItem="True" x:Name="lstResults" >
         <StackPanel Orientation="Horizontal" >
           <Image Height="100" Width="100" 
             Source="{Binding Path=ImageURL}"/>
             <TextBlock Text="{Binding Path=Text}"/>
             <TextBlock Text="{Binding Path=ScreenName}"/>
             <TextBlock Text="----------"/>
Finally, the following code puts it all together to both query and display the Twitter data.

   Dim TwitterLib As New TwitterLib
   Dim URL As String = _
   Dim Results As String = TwitterLib.GetTweet(URL)
   Dim JsonSerializer As New  _
   Dim ReturnObject As Object = _
   Dim StatusList As New List(Of Status)
   For Each StatusObject As Object In CType(ReturnObject, Array)
     StatusList.Add(New Status With _
        { _
        .Text = StatusObject("text"), _
        .ScreenName =  StatusObject("user")("screen_name"), _
        .ImageURL = StatusObject("user")("profile_image_url") _
   Me.lstResults.ItemsSource = StatusList
The code requests the timeline for rodpaddock in JSON format, and converts the returned data to a .NET array using the JSON serializer. That array is then transformed into a list of simple POCO (Plain Old CLR Objects) which the sample WPF form displays.

You can see the final results of this in Figure 2.

Figure 2. Simple Twitter WPF Client: Here are the results of querying Twitter for the rodpaddock timeline.

Twitter Complete

The Twitter API might look daunting at first, but with a simple set of tools and techniques you can Twitter-enable your applications in a matter of minutes. And if you are looking for something to follow on Twitter, check out the following:

  • http://twitter.com/codemagazine
  • http://twitter.com/codecast
For more information about programming Twitter, check out these resources:

Rod Paddock is Editor-in-Chief of CoDe Magazine.
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date