« How to set your Twitter status using the Twitter api with VB.Net? »
Tue May-12-2009, 7:25:48 PM
So, as promised in my previous blog entry, this is how I use the Twitter api with VB.Net to set my Twitter status and to get my Twitter Status.

The setTwitterStatus function accepts three parameters, the username, password and the status.

You can download the full source code near the end of this article.

    'Using Webclient With Credentials To Set Twitter Status
    Public Function setTwitterStatus(ByVal user As String, ByVal pass As String, ByVal status As String) As String
        Dim url As String = "http://twitter.com/statuses/update.xml?status=" & status
        Dim HTMLSource As String = ""
        Dim WC As New WebClient
        WC.Credentials = New NetworkCredential(user, pass)
        HTMLSource = WC.UploadString(url, "")
        Return parseTwitterXML(HTMLSource)
    End Function

    'Parse The Twitter Response XML
    Public Function parseTwitterXML(ByVal XML As String) As String
        Dim Str As String = ""
        Dim XDoc As New XmlDocument
        Dim XNode As XmlNode
        For Each XNode In XDoc.DocumentElement.SelectNodes("//status")
            Str += XNode.Item("created_at").InnerText & ", " & XNode.Item("text").InnerText & vbNewLine & vbNewLine
        Return Str
    End Function