DCSIMG
How to send Twitter direct messages from PowerShell - Shay Levy

Shay Levy

If you repeat it, PowerShell it!

How to send Twitter direct messages from PowerShell

This function sends a direct message (DM) from your Twitter account to another Twitter user, notice that you can only send a direct message to a person who follows you.


function Send-DirectTweet($Recipient,$Message,$UserName,$Password){
  
$url="http://twitter.com/direct_messages/new.xml?user=$Recipient&text=$Message"
  
$request = [System.Net.WebRequest]::Create($url)
  
$request.credentials= New-Object System.Net.NetworkCredential($UserName,$Password)
  
$request.method= "POST"
  
$request.contentType = "application/x-www-form-urlencoded"
  
$request.GetResponse().statusCode # return the status code of the request
}

# sample usage
Send-DirectTweet -Recipient twitterUser -Message Hi -UserName yourUserName -Password yourPassword

Comments

Send a Tweet from PowerShell « Bhargav Shukla???s IT Playground said:

Pingback from  Send a Tweet from PowerShell « Bhargav Shukla???s IT Playground

# March 16, 2010 7:25 AM

Bhargav Shukla said:

Shay,

I used your framework to create script for status updates. I also made it more secure by using SSL which won't be a bad idea for your script either! Here's my script link: http://bit.ly/dAAqbU.

Thanks!

Bhargav

# March 16, 2010 7:38 AM

ScriptFanatic said:

Cool, thanks for the link.

# March 16, 2010 7:26 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Enter the numbers above: