Who is Following you on Twitter

List your Twitter Followers programmatically using this VbScript. It use some XML functions to get the right data our of Twitter.

Who is Following you on Twitter

It can be very convenient to have a script that can check who is following you on Twitter. The script on this page retrieves an XML file from Twitter, with an overview of who is following you.

Setting up the script
Copy and paste the script in the box below and save it as a VbScript file. Scroll down to around line 27 to 29 in the script and there you will find the three varaibles you have to change into you own Twitter login information to get it working. This script lacks validation, for readability.

When you test this script on an account with zero followers you might experience an error. Keep that in mind when deploying this script in your own application. The script is heavily commented, so start at the top and work you way down, then you will probably understand what´s going on!

' Scriptname: ListFollowers.vbs
' With this script you can update your Twitter status
' August 2009 - Erick Hiemstra
' more info:
' http://sitejunction.awardspace.com/vbscript_tweets/list_followers/

OPTION EXPLICIT 'Be sure you have declared all your variables.

' ----------------------------------------------------
' In this script the response is hardcoded directly into a variable
' to keep the script readable, but could of
' course come from whatever source.
' ----------------------------------------------------

Dim strUserName, strPassword, strScreenName
strScreenName = "MyUsername" ' Your Twitter username
strUserName = "me@email.com" ' Your Twitter username
strPassword = "MyPassword" ' Your Twitter password

' ----------------------------------------------------
' This is where the job is started
' it actually is made out of two pieces
' ----------------------------------------------------

' First get the XML file with your followers and store the result in a variable.
Dim strTwitterXMLResponse
strTwitterXMLResponse = ListTwitterFollowers(strScreenName, strUserName, strPassword)

' .. and second, parse the XML result into a more readable or
' useable parts

' ----------------------------------------------------
' This is where the actual work is done
' ----------------------------------------------------

Function ListTwitterFollowers(strScreenName, strUserName, strPassword)

     ' It uses XMLHTTP to contact the Twitter website
     ' it uses your login information here to authenticate you.
     Dim objHTTP
     Set objHTTP = CreateObject("Microsoft.XMLHTTP")
          objHTTP.open "GET", "http://twitter.com/statuses/followers.xml?screen_name=" & strScreenName, false, strUserName, strPassword
          objHTTP.send ()
          ' Store the Twitter response to the result of the function so you can use this later
          ListTwitterFollowers = objHTTP.responseText
     Set objHTTP = nothing 'Release the object
End Function

Sub ReadXMLFile(strXML)
     ' This sub makea the XML response more readable.
     ' Load the XML
     Dim xmlDoc
     Set xmlDoc = CreateObject("Microsoft.XMLDOM")
     xmlDoc.loadXML strXML

     ' point to the right place in the XML file. If you connect to an account
     ' without followers this is the part which will drop an error, because when
     ' there are no followers, the tag named "user" does not exist, so an error
     ' is presented. But we assume you have followers, so no error trapping is built in!
     Dim objNode
     Set objNode = xmlDoc.getElementsByTagName("user")

     ' Loop through the XML and only return the "screen_name" element value
     Dim strMessage, i
     For i = 0 to objNode.Length - 1
          strMessage = strMessage & objNode(i).getElementsByTagName("screen_name")(0).childNodes(0).nodeValue & VbCrlf

     Set xmlDoc = nothing ' Release the object

     ' Here the result is stored in a variable and shown in a messagebox
     ' just to show you how it is done. You can use this for more advanced
     ' features!
     MsgBox strMessage

End Sub

You can also download the script directly here. Right click with you mouse on the download link, choose "save as" and save the file. Change the extension to *.vbs!

Do you have got problems with this script? You can send me an e-mail. I do have a Twitter account as well. I don't mind if you add me or send me some testing messages. So add me to your following list as you like and don't mind sending me test messages. You can find me at http://twitter.com/sitejunction

« previous: HTA script | next (will follow soon...) »