Follow me on Twitter at Twitter.com/wbm
FYI, I'm blogging most of my stuff over at More Wally now.
You might want to add my rss feed to your reader at:http://morewally.com/cs/blogs/wallym/rss.aspx
Twitter API - Sending a Direct Message in C# - Wallace B. McClure

Wallace B. McClure

All About Wally McClure - The musings of Wallym on .NET, Sql, ASP.NET, and other crazy shenanigans

News

Personal Blog

Work Blog

.NET

Book Authors

Business

Family

Friends

Georgia Tech Bloggers

Personal

Twitter API - Sending a Direct Message in C#

I tried writing some code to send a direct message using the Twitter API. It was a FAIL.  I did some searching in google, and found this method below listed in a google group.  I didn't write it, but it works, so enjoy.  I plugged the method into my WCF Service and it just worked.

         [OperationContract]
        public void DMSend(string username, string recipient, string tweet)
        {
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://twitter.com/direct_messages/new.xml?user=" + recipient + "&text=" + tweet);
            req.Method = "POST";
            req.Credentials = new NetworkCredential(username, password);
            req.ContentLength = 0;
            req.ContentType = "application/x-www-form-urlencoded";
            WebResponse response = req.GetResponse();
        }

Original Url: http://morewally.com/cs/blogs/wallym/archive/2009/03/19/twitter-api-sending-a-direct-message-in-c.aspx

Comments

dolly said:

what are the credentials in this code of twitter API

# April 22, 2009 3:19 AM

dgman said:

this doesn't work on mine. been trying all day.

are you sure about this?

HttpWebRequest req = (HttpWebRequest)WebRequest.Create("twitter.com/.../new.xml + recipient + "&text=" + tweet);

I'm using .net, and this isn't doing anything at all.

# May 28, 2009 2:19 PM
Leave a Comment

(required) 

(required) 

(optional)

(required)