Reading a tweeters timeline using PowerShell


Since, it is holiday season and I had some time on my hands I was reading about the REST API on Twitter and got to thinking if I could read the Twitter time line of a user, any user I was interested in directly from the console? The answer is yes. So, I quickly brewed a PowerShell script to read tweets of users.

You may ask why Powershell? The answer is quite simple. It is a well-established fact that PowerShell is a very powerful tool and there is no arguing that you could do ‘almost anything’ using it. Also, I love it.

There is a to do list 🙂

  • I would’ve liked to throw in some more formatting but, since this was a proof of concept script I did not get it in. I would like to get back to this sometime in the near future get the output a little more readable.
  • I would like to process this for a list of users, instead of the one user I process right now.
  • Maybe put it in Perl using Mechanize…nah, just kidding 🙂
###########################################################################
#
# NAME: Get-TwitterStream
#
# AUTHOR: @SqlChow
#
# COMMENT: 
#
# COPYRIGHT: © 2011 SqlChow. Code provide as is. User discreetion required.
#
# VERSION HISTORY:
# 1.0 12/25/2011 - Initial release
#
########################################################################### 

Function Get-TwitterStream{
param(
[parameter(Mandatory=$true)]
[ValidateNotNullOrEmpty()]
[String]
$UserName
) 

try
{
$objWebClient = New-Object System.Net.WebClient 

#uncomment below block if you use a proxy.
#[String]$webProxy = "IpAddress of your proxy here"
#$objWebProxy = New-Object System.Net.WebProxy($webProxy,)
#$objWebProxy.UseDefaultCredentials = $true
#$objWebClient.Proxy = $objWebProxy 

$strTwitURL = "http://api.twitter.com/1/statuses/user_timeline.xml?screen_name=$UserName&count=20&page=1"
Write-Debug $strTwitUrl
$strContentString = $objWebClient.DownloadString($strTwitURL)
$xmlContents = [xml]$strContentString 

$xmlContents.statuses.ChildNodes|Format-Table -Property text -AutoSize -Wrap
}
catch
{
Write-Error "Unable to get stream data"
}
finally
{
$objWebClient.Dispose()
}
}
 
Get-TwitterStream

PaulRandal and BrentO's tweets

 
Advertisements
About

By profession, I’m a SQL Server Database Administrator. I love to poke my nose into different corners and see how stuff looks in there. I keep looking for new things to do as my mind refuses to settle on one topic.

Tagged with: , , , , ,
Posted in PowerShell
One comment on “Reading a tweeters timeline using PowerShell
  1. Use my PSTwitter module:

    Powershell Twitter REST API 1.1 Module on TechNet Gallery… https://goo.gl/s7pmmA

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: