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 Web, HTML5, Mobile, Xamarin.iOS, Xamarin.Android, and Windows Azure.

News

Visual Studio Magazine Column Personal Blog

.NET

Book Authors

Business

Family

Friends

Georgia Tech Bloggers

Personal

Archives

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

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