Using Twitter API with ASP

Posted on Monday, March 26, 2007 02:05 PM by K. Latham
I was playing with the Twitter API today. I created a function to post to Twitter every time I add someone to the Blog Oklahoma web ring.

Here's the function I put together using ASP.

Function PostToTwitter(strStatus)
Dim strText
Dim strURL
Dim objHttp
    strText = ""
    strURL = "http://twitter.com/statuses/update.xml?status=" & Server.URLEncode(strStatus)
    set objHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
    if err.number <> 0 then set objHttp = Server.CreateObject("Microsoft.XMLHTTP")
    objHttp.open "POST", strURL, false, "(user-name-here)", "(password-here)"
    objHttp.Send
    if objHttp.status <> 200 then
        strText = "HTTP Error: " & objHttp.status & " - " & objHttp.statusText
    else
        strText = objHTTP.responseText
    end if
    set objHttp = nothing
    PostToTwitter = strText
End Function

strReturnValue = PostToTwitter("Your Twitter Post Here")


twitter.com/programwitch