Twitter API - Submit a post in C# - More Wally - Wallace B. McClure
in

MoreWally.com

Giving people what they want, More Wally. This is the technical and personal blog site of
Wallace B. (Wally) McClure.

This Blog

Syndication

Technical Sites

Archives

More Wally - Wallace B. McClure

This blog will have all kinds of posts about Wally McClure. In it, there will be tons of .NET and computer programming posts as well as Wally's views on life in general. As you might guess, this site and blog help you get More Wally in your life. What more could anyone want? iPhone, Android, Xamarin.iOS, Xamarin.Android, Mobile, HTML5, .NET, ADO.NET, ASP.NET, AJAX, jQuery, jQuery Mobile, ASP.NET AJAX, and Windows Azure............follow me on twitter at Wally

Twitter API - Submit a post in C#

I used C# and WCF, but I could have just as easily used an ASMX web service.  This code is fairly simple.  No I didn't write it initially.  I found it online (Hey, we all have to start somewhere).  I massaged it a little to fit my needs and boom, here it is.  I have decided to leave the comments for the original code sample in the post.  Note: This code will not run as listed.  You have to have a password.  This code has that as a shared variable, but I'm not showing that to you, seriously.  I hope that this is of some help to you.

        [OperationContract]
        public void SubmitUserStatus(string username, string tweet)
        {
            // encode the username/password
            string user = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(username + ":" + password));
            // determine what we want to upload as a status
            byte[] bytes = System.Text.Encoding.ASCII.GetBytes("status=" + tweet);
            // connect with the update page
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://twitter.com/statuses/update.xml");
            // set the method to POST
            request.Method = "POST";
            // thanks to argodev for this recent change!
            request.ServicePoint.Expect100Continue = false;
            // set the authorisation levels
            request.Headers.Add("Authorization", "Basic " + user);
            request.ContentType = "application/x-www-form-urlencoded";
            // set the length of the content
            request.ContentLength = bytes.Length;
            // set up the stream
            Stream reqStream = request.GetRequestStream();
            // write to the stream
            reqStream.Write(bytes, 0, bytes.Length);
            // close the stream
            reqStream.Close();
        }

Comments

 

Dew Drop - Weekend Edition - March 21-22, 2009 | Alvin Ashcraft's Morning Dew said:

Pingback from  Dew Drop - Weekend Edition - March 21-22, 2009 | Alvin Ashcraft's Morning Dew

March 22, 2009 8:39 AM
 

Community Blogs said:

I used C# and WCF, but I could have just as easily used an ASMX web service. This code is fairly simple

March 25, 2009 6:13 AM
 

Twitter Commands said:

Listed below are links to blogs that reference this entry: Russians blamed DoS attack on Twitter, Facebook, LiveJournal, Google Blogger and YouTube.

August 17, 2009 6:07 AM
 

Twitter API – Submit a post in C# « Zhuxiaodong’s Weblog said:

Pingback from  Twitter API – Submit a post in C# « Zhuxiaodong’s Weblog

March 21, 2010 10:44 AM
 

Twitter API – Submit a post in C# « .net 4.0 « Object Oriented Programing said:

Pingback from  Twitter API – Submit a post in C# « .net 4.0 « Object Oriented Programing

April 23, 2011 12:14 PM
2006 - Wallace B. McClure
Powered by Community Server (Non-Commercial Edition), by Telligent Systems