Dustin Wheeler

Dustin Wheeler
Dustin is a technology-driven CPA in Orem, Utah.

Social Media

Follow me on Twitter

How I Created my own Twitter App with Visual Basic

Over the past few weeks, I have spent countless hours programming (and testing and reprogramming and testing and reprogramming, etc.) a Twitter app I created in Visual Basic.  It was the most fun project I could think of for a Visual Basic class I’m taking at UNLV.  In the end, the programming wasn’t so difficult.  It just took me a long time to find something that worked.  After many Google searches, I couldn’t find a straight-forward walkthrough, so hopefully this blog post will be helpful to some lost soul out there (maybe for another school project).  Below is a screen shot of my app.

Twitter App Created with Visual Basic

The only action my form does with Twitter is post an update when the “to Twitter” checkbox is checked.  The other buttons read, write, edit and delete tweets in a Microsoft Access database.

First, I created the form above, including the labels, text boxes, and buttons.  I won’t go into the code behind each one of them, but the code for the label with the number of characters remaining was particularly fun to write.  I made its actions similar to what is on Twitter’s webpage.  When the number of characters in the status text box (rtbStatus) goes over 140, the text turns red and the “tweet” button is disabled.  The code is:

Private Sub rtbStatus_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rtbStatus.TextChanged
lblTweetLength.Text = 140 – rtbStatus.TextLength
If lblTweetLength.Text < 0 Then
lblTweetLength.ForeColor = Color.Red
End If
If rtbStatus.TextLength = 0 Or rtbStatus.TextLength > 140 Then
btnTweetToDatabase.Enabled = False
Else
btnTweetToDatabase.Enabled = True
End If
End Sub

Next, I went to the Twitter Developers webpage and registered my application (funny, I never thought I’d be a Twitter developer).  After filling out a form describing my app, I received a consumer key, consumer secret, access token, and access token secret.  These are needed to authorize your application to access your Twitter account.

Then, I went to the TwitterVB webpage, which is an open source project with a .NET library that allows desktop and web applications to communicate with Twitter.  I downloaded the TwitterVB zip file.  The zip file contains many different files, but the only one I used was TwitterVB.dll.  In Visual Basic, I added the dll file as a reference.

I included the namespace in my code file with the following:

Imports TwitterVB2

I then added the following code that I found from the TwitterVB webpage to the code that executes when the “tweet” button is clicked and the “to Twitter” checkbox is checked.  I replaced the consumer key, consumer secret, access token, and access token secret in the code with what I had received from the Twitter Developers webpage when I registered my application.

Dim TextToTweet As String
TextToTweet=rtbStatus.Text
Dim tw As New TwitterVB2.TwitterAPI
tw.AuthenticateWith(“consumerkey”,“consumersecret”,“oauthtoken”,“tokensecret”)
tw.Update(TextToTweet)

Then, I tested my app.

Testing my Twitter App

After I clicked the “tweet” button, I opened my Twitter timeline in my web browser and saw that my tweet successfully posted to Twitter!  It even shows that it posted via DustinVB, which is what I named my app when I registered it with Twitter.

My Test Tweet in a Web Browser

After I turn this project in to be graded, it will collect dust in my virtual bookshelf.  I don’t plan to use it again.  There are so many good Twitter programs out there that can do so much more than mine can.

Still, I feel happy that I figured it out and can now call myself a Twitter developer (even though I’m a novice, at best).

12 comments to How I Created my own Twitter App with Visual Basic

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>