Powershell to Twitter
I have too much time on my hands this morning. The following script makes it easy to get and set Twitter status. I’ve seen similar ones elsewhere but they all seemed to have external dependencies, this one does not.
twitter.ps1:
$script:username = "foo"
$script:password = "bar"
function get-twitter
{
$wc = new-object System.Net.Webclient
$wc.Credentials = new-object System.Net.NetworkCredential $script:username,$script:password
$rest = $wc.DownloadString("http://twitter.com/statuses/friends_timeline.xml")
$xml = [xml]$rest
$xml.statuses.status
}
function set-twitter
{
param($status)
$wc = new-object System.Net.Webclient
$wc.Credentials = new-object System.Net.NetworkCredential $script:username,$script:password
[System.Reflection.Assembly]::LoadWithPartialName("System.Web") | out-null
$encodedstatus = [System.Web.HttpUtility]::UrlEncode($status)
$postdata = "status=$encodedstatus"
$postbytes = [System.Text.Encoding]::ASCII.GetBytes($postdata)
$wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded")
[System.Text.Encoding]::ASCII.GetString($wc.UploadData("http://twitter.com/statuses/update.xml", $postbytes))
}





Ah! You beat me to it
Thanks anyway.
Kris
2 Sep 08 at 10:35 pm