Update: Twitter “statuses/followers” API documentation had a small note at the bottom that says it returns only 100 followers if no paging is used. I have updated the script accordingly. Thanks to @RamyMahrous for notifying me in his comment below.
For a long time I thought that @DotNetArabi shouldn’t follow it’s own followers due to various reasons I had, but lately I discovered that I was wrong. So I have decided to follow them back no matter how many they are, but that would be a tedious thing to do manually. Here comes Powershell to the rescue.
I wrote the following Powershell script in Powershell ISE (the Integrated Scripting Environment), which is already shipped with Win7, utilizing Twitter’s APIs, and it did the trick:
$wc = New-Object System.Net.WebClient
$wc.Credentials = New-Object System.Net.NetworkCredential "dotnetarabi", "UseYourOwnPWbuddy!"
$cursorCount = "-1"
do {
$rest = $wc.DownloadString("http://api.twitter.com/statuses/followers.xml?cursor=" + $cursorCount)
$xml = [xml]$rest
foreach ($user in $xml.users_list.users.user) {
$wc.UploadString("http://api.twitter.com/1/friendships/create/" + $user.screen_name + ".xml", "")
}
$cursorCount = $xml.users_list.next_cursor
}
while ($xml.users_list.next_cursor -ne "0")
It’s simple and straightforward; I used the “UploadString” method of the WebClient class because it produces a “POST” HTTP request required by Twitter API rather than “GET”. Note that the response you get from the “Create” API will be either an XML representation of the followed-user entity, or a server error “Forbidden” for many reasons Twitter may have. This is how you will know if each “follow” procedure succeeded or not.
Thanks to Helge Klein I could highlight my Powershell script by his script here