- <Window x:Class="MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="410" Width="732">
- <Grid Background="#FFA6C3F5" OpacityMask="#FF2271F2" Width="689">
- <TextBox Height="23" HorizontalAlignment="Left" Margin="193,42,0,0" Name="txtinput" VerticalAlignment="Top" Width="180" Text="" BorderBrush="#FFE6EB2D" />
- <Button Content="show" Height="28" HorizontalAlignment="Right" Margin="0,40,202,0" Name="btnshowresult" VerticalAlignment="Top" Width="88" Foreground="#FF1510B5">
- <Button.BorderBrush>
- <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
- <GradientStop Color="Black" Offset="0" />
- <GradientStop Color="#FF22F4DC" Offset="1" />
- </LinearGradientBrush>
- </Button.BorderBrush>
- </Button>
- <ListBox HorizontalAlignment="Left" Margin="410,93,0,34" Name="lsttweets" Width="263" OpacityMask="#FF908D8D" BorderBrush="#FFECF13B">
- <ListBox.Foreground>
- <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
- <GradientStop Color="Black" Offset="0" />
- <GradientStop Color="#FFE71E1E" Offset="1" />
- </LinearGradientBrush>
- </ListBox.Foreground>
- </ListBox>
- <Label Content="User Name /Iinput" Height="28" HorizontalAlignment="Left" Margin="70,40,0,0" Name="lblinput" VerticalAlignment="Top" Width="117" Foreground="#FF2042E4" Visibility="Visible" />
- <ListBox Margin="0,127,440,69" Name="lstmentions" HorizontalAlignment="Right" Width="109" BorderBrush="#FFEFF429">
- <ListBox.Foreground>
- <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
- <GradientStop Color="Black" Offset="0" />
- <GradientStop Color="#FFC318ED" Offset="1" />
- </LinearGradientBrush>
- </ListBox.Foreground>
- </ListBox>
- <ListBox HorizontalAlignment="Right" Margin="0,127,305,69" Name="lsthashtags" Width="110" BorderBrush="#FFEFF435">
- <ListBox.Foreground>
- <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
- <GradientStop Color="Black" Offset="0" />
- <GradientStop Color="#FFFAD013" Offset="1" />
- </LinearGradientBrush>
- </ListBox.Foreground>
- </ListBox>
- <Label Content="Tweets" Height="28" HorizontalAlignment="Left" Margin="528,59,0,0" Name="Label1" VerticalAlignment="Top" Width="54" Foreground="#FF1A34DF" />
- <ListBox Height="175" HorizontalAlignment="Left" Margin="12,127,0,0" Name="ListBox1" VerticalAlignment="Top" Width="108" BorderBrush="#FFECF141">
- <ListBox.Foreground>
- <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
- <GradientStop Color="Black" Offset="0" />
- <GradientStop Color="#FF73E214" Offset="1" />
- </LinearGradientBrush>
- </ListBox.Foreground>
- </ListBox>
- <Label Content="Hashtags" Height="28" HorizontalAlignment="Right" Margin="0,93,335,0" Name="Label2" VerticalAlignment="Top" Foreground="#FF2E48EE" />
- <Label Content="Mentions" Height="28" HorizontalAlignment="Left" Margin="169,93,0,0" Name="Label3" VerticalAlignment="Top" Width="54" Foreground="#FF1532EE" />
- <Label Content="Mentions & Hashtags" Height="28" HorizontalAlignment="Left" Margin="12,93,0,0" Name="Label4" VerticalAlignment="Top" Width="108" Foreground="#FF1E3AE8" />
- <Label Height="28" HorizontalAlignment="Right" Margin="0,317,316,0" Name="Label5" VerticalAlignment="Top" Width="79" Foreground="#FFC11111" Background="#FFBDD5F2" />
- <Label Height="28" HorizontalAlignment="Left" Margin="154,317,0,0" Name="Label6" VerticalAlignment="Top" Width="77" Background="#FFB9D4F5" />
- <Label Content="Twitter" Height="26" HorizontalAlignment="Left" Margin="311,0,0,0" Name="Label7" VerticalAlignment="Top" Width="52" FontWeight="Bold" FontStyle="Italic" FontStretch="Expanded" Foreground="#FFEBF10F"></Label>
- </Grid>
- </Window>
- 'Copy all imports
- Imports System.Net
- Imports System.IO
- Imports System.Xml
- Class MainWindow
- 'Copy this function
- 'Function takes username as a string and page number
- 'and returns a list containing the last 50 tweets
- 'made by the user
- 'Page is the page number containing the tweets and starting
- 'with 1, to get more tweets you simply get page 2, then 3 ..etc
- Function getTweets(ByVal username As String, ByVal page As Integer) As List(Of String)
- Dim URL = "http://api.twitter.com/statuses/user_timeline/" & username & ".xml?count=50&page=" & page
- Dim tweets As New List(Of String)
- Dim Request As HttpWebRequest = HttpWebRequest.Create(URL)
- Request.Method = "GET"
- Dim Response As WebResponse = Request.GetResponse
- Dim Reader As New StreamReader(Response.GetResponseStream)
- Dim Results As String = Reader.ReadToEnd
- Reader.Close()
- Response.Close()
- Dim Doc As New XmlDocument
- Doc.LoadXml(Results)
- Dim XMLNodes As XmlNodeList = _
- Doc.SelectNodes("//statuses/status/text")
- For Each Node As XmlNode In XMLNodes
- tweets.Add(Node.InnerText)
- Next
- Return tweets
- End Function
- Private Sub btnshowresult_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnshowresult.Click
- Dim username As String = txtinput.Text
- Dim tweet1 As List(Of String) = getTweets(username, 1)
- Dim tweet2 As List(Of String) = getTweets(username, 2)
- For Each t In tweet1
- lsttweets.Items.Add(t & ControlChars.NewLine)
- Next
- For Each t In tweet2
- lsttweets.Items.Add(t & ControlChars.NewLine)
- For Each tweet In t.Split
- If tweet.Contains("#") Then
- lsthashtags.Items.Add(t)
- End If
- Next
- For Each twt In t.Split
- If twt.Contains("@") Then
- lstmentions.Items.Add(t)
- End If
- Next
- Next
- End Sub
- End Class