My twitter updates are done using a variety of code. At the moment I use the Curl command line in conjunction with SlickRun. In the past I did this with Outlook (see the article Twittering from Outlook Using VBA). In the past I’ve found this pretty easy to do using the Twitter Api.
I also like to do updates from my Pocket PC, but am not keen on SMS charges. The solution of course is to create my own client, which I’ll be posting about shortly.
For my client program I intend to use TwitterLib library. Sadly this does not work for the compact framework unaltered. I am currently working on porting it to the compact framework.
In the interim I want to share with you a simple code sample for submitting tweets to Twitter.
The example is simple enough to be used by people who want to do HTTP posts to similar services.
Dim lsParams As String = "status=" & Uri.EscapeDataString(tweetText)
Dim loRequest As HttpWebRequest = CType(HttpWebRequest.Create("http://twitter.com/statuses/update.xml"), HttpWebRequest)
.Proxy = System.Net.GlobalProxySelection.GetEmptyWebProxy()
.Timeout = 10000
.AllowAutoRedirect = True
.AllowWriteStreamBuffering = True
.Method = "POST"
.ContentType = "application/x-www-form-urlencoded"
.ContentLength = Len(lsParams)
Dim loCred As New System.Net.NetworkCredential("someusername", "somepassword")
.Credentials = loCred
' Write the request paramater
Dim stOut As New StreamWriter(.GetRequestStream(), System.Text.Encoding.ASCII)
Dim loResp = .GetResponse
The most important difference with the full .net framework is the “GetEmptyWebProxy” and “AllowWriteStreamBuffering” lines. It won’t work without it.
|Share this post :|