Twittering using the Compact Framework
Posted by anoriginalidea on May 19, 2008
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) .Timeout = 10000 .Method = "POST"
.ContentType = "application/x-www-form-urlencoded" Dim loCred As New System.Net.NetworkCredential("someusername", "somepassword") ' Write the request paramater Dim loResp = .GetResponse .Close() End With
With loRequest
.Proxy = System.Net.GlobalProxySelection.GetEmptyWebProxy()
.AllowAutoRedirect = True
.AllowWriteStreamBuffering = True
.ContentLength = Len(lsParams)
.Credentials = loCred
Dim stOut As New StreamWriter(.GetRequestStream(), System.Text.Encoding.ASCII)
stOut.Write(lsParams)
stOut.Flush()
stOut.Close()
With loResp
End With
The most important difference with the full .net framework is the “GetEmptyWebProxy” and “AllowWriteStreamBuffering” lines. It won’t work without it.


Beetle said
It is nice tutorial
Wolowizard said
Hello.
I need your help.
On VS.NET 2008 – ppc + .net cf 2.0, I pasted the above under a button. I made some changes: & Uri.EscapeDataString(”tweet text to post”)
And added username and pass.
For the line [Dim loRequest As HttpWebRequest = ] the HttpWebRequest is said to be NOT DEFINED.
I don’t know what to do.
Streamwriter is NOT defined as well.
.Close – it says that targeted framework does not support late binding.
What should I do? Install .NET CF 1.0?
Help me.
Thanks.
Wolowizard.
anoriginalidea said
You need to get a reference to System.Web….