Posting Status Updates (Tweets) To A Twitter Profile Via ASP.NET
I have a client that posts several news stories to its Web site every day. So it makes tremendous sense for them to post the headlines to Twitter as tweets, so that followers might be informed of breaking news, or just what’s new on the site.
The Twitter API makes posting status updates (tweets) to Twitter as simple as invoking a WebRequest. Unfortunately, most of the ASP.NET examples on the Web that aim to show you how to post status updates are either written in C#, have coding errors, simply will not work, or all three.
So here’s a simple VB.NET subroutine that will post tweets.
Sub TwitIt(ByVal strUser As String, ByVal strPass As String, ByVal strMessage As String)
'this subroutine requires your ASP.NET page to have a label control with an ID of lblStatus
'create post variable for tweet
Dim strTweet As String = "status=" & Server.HtmlEncode(strMessage)
'convert post variable to byte array for transmission purposes
Dim bRequest As Byte() = System.Text.Encoding.ASCII.GetBytes(strTweet)
Try
'create HttpWebRequest to status update API resource
Dim objRequest As HttpWebRequest = WebRequest.Create("http://twitter.com/statuses/update.xml")
'pass basic authentication credentials
objRequest.Credentials = New NetworkCredential(strUser, strPass)
'set method to post and pass request as a form
objRequest.Method = "POST"
objRequest.ContentType = "application/x-www-form-urlencoded"
'tell the server it will not receive a 100 Continue HTTP response
objRequest.ServicePoint.Expect100Continue = False
'set content length of request
objRequest.ContentLength = bRequest.Length
'capture the stream (content) of the request
Dim objStream As Stream = objRequest.GetRequestStream()
'put the bytes into request
objStream.Write(bRequest, 0, bRequest.Length)
'close the stream to complete the request
objStream.Close()
'uncomment line below to report success
'lblStatus.Text = "Tweet sent!"
'You can also capture the XML response Twitter sends back
'uncomment lines below to capture responses
'Dim objResponse As WebResponse = objRequest.GetResponse()
'Dim objReader As New StreamReader(objResponse.GetResponseStream())
'lblStatus.Text = objReader.ReadToEnd()
Catch ex As Exception
'uncomment line below to report ASP.NET errors
'lblStatus.Text = ex.Message
End Try
End Sub
Continue reading: Posting Status Updates (Tweets) To A Twitter Profile Via ASP.NET »
Most Code Downloads Restored; Some Articles Deleted
I’ve restored about two-thirds of the code downloads on the site, especially for the most popular articles on this site. I’ve also had to delete some articles that were either based on images I can no longer locate or were, to be blunt, badly written.
Bear with me; I should have the last of the code downloads reinstated over the next few days.
Also, be aware that certain trackback / inline links on this site may now be dead, as a result of the aforementioned post prunings.
Describing ‘Red’ To A Blind Man: The Dilemma Of Ontology
Recently asked on Yahoo! Answers:
How to map a keyword to a category?
I have a bunch of general categories, such as: Games, Modeling, Business, Finance, etc.My question is, how can I take a keyword such as “Xbox 360″ and automatically map it to a category such as “Games”? This is an easy example, and I did figure out ways to do this, but if I take a harder example such as “Tyra Banks”, I am unable to map it to a category of mine such as “Modeling” or “Tv Shows”.
I have been thinking of this for a very long time, and I can’t come up with a concrete solution. I have also searched the web and found nothing that would provide this service.
Any ideas?
Basically, computers develop semantic understanding the same way we people do, only far less efficiently: Repetition of example. (In computer science, semantics are called ontology.)
The reason we are far more efficient is that we more easily create connections between things, and more quickly process those connections, than computers can manage.
For example, suppose I give you three categories: colloid, coagulant, polymer. Now, place “chocolate milk” into the proper category.
Continue reading: Describing ‘Red’ To A Blind Man: The Dilemma Of Ontology »
An Open Letter To A Programming Noob
Recently received in my e-mail:
Hi There
Found your email on your blog via the contact me which is linked to on your [Yahoo! Answers] profile.
I was curious as to what languages you program in as I am keen to get into programming and wanted any advise or recomendations for books.
I have done quite a bit of visual basic 6 which I know is not OOP.
Would be good to either do vb 2005 or c++ or java
Thanks
Shane
My response to this e-mail follows.
A New Approach To Yahoo! Answers
Those of you who know me from Yahoo! Answers may be wondering why you don’t see quite as much of my answers around. As recently as last week, I was answering as many as 60 questions a day.
Part of that is now that the holidays have passed, I’m busier with paying projects. But a bigger reason is that I’ve rethought which questions I am going to answer. It occurred to me recently that there’s a huge difference between quantity and quality, and in addition, I’m taking a bit more offense than I should with poorly worded questions, stupid questions and people who reward wrong answers with “Best Answer.”
I know full well when I answer a question whether the questioner even understands what he is asking, nonetheless the answer I give. And I know, even better, the cliche that one should never teach pigs to sing, because it wastes your time and annoys the pig.
I also know better than to answer when it’s not needed or counterproductive, and it occurs to me that not following my own common sense makes me a fool.

