Follow me on Twitter at
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:
Twitter API - Sending a Direct Message in C# - Wallace B. McClure

Wallace B. McClure

All About Wally McClure - The musings of Wallym on Web, HTML5, Mobile, Xamarin.iOS, Xamarin.Android, and Windows Azure.


Visual Studio Magazine Column Personal Blog


Book Authors




Georgia Tech Bloggers



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.

        public void DMSend(string username, string recipient, string tweet)
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create("" + 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:


dolly said:

what are the credentials in this code of twitter API

# April 22, 2009 3:19 AM

Srini said:

that's true. even it is not working for me also.  it is giving basic authentication is not supported now.  it is true. twitter is now moved to oauth authentication.  pl tell me how can we achieve the same using oAuth.

# January 22, 2011 10:27 AM