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).

Tags: ,

Trackback from your site.

Comments (13)

  • Avatar

    Jason M Blumer, CPA

    |

    This is so cool, Dustin. Of the #GeeksUnite crew, you are the official programmer now. Don’t forget it!

    Reply

  • Avatar

    John Lynn

    |

    This is awesome. You’re a brave soul indeed. Twitter has a nice API, but it still is pretty technical to get it to work. Nicely done!

    Reply

  • Avatar

    Kara Haas

    |

    Dustin! Second the above posts. You have been my tech support on multiple occasions – so don’t be thinking dust will be collecting. Besides, the mere power of testing and doing makes it that much easier to explain, troubleshoot and/or support the fantastic apps out there. Oh yeah, and makes us appreciate the work — which often is taken for granted in accounting and tech industries. Bravo!

    Reply

  • Avatar

    hadi

    |

    thanks.

    Reply

  • Avatar

    Jim Wyman

    |

    Dustin,
    Nice Find! Do you know of another place to get TwitterVB2? IT apparently is now gone off the site and I can’t find it anywhere else..

    Jim

    Reply

  • Avatar

    Dustin Wheeler

    |

    Jim – I don’t, but if anyone leaves a comment with an answer I’ll e-mail you.

    Reply

  • Avatar

    Danny

    |

    CodePlex does not have twittervb.dll nor twittervb2 to be downloaded.
    Anyone of you having those file to share?

    Reply

  • Avatar

    Rhys

    |

    really useful thanks!

    @Danny, i have twittervb.dll if you want it

    Reply

  • Avatar

    Hans

    |

    @Rhys, can you send me the twittervb.dll as well, please?

    Reply

  • Avatar

    Daan

    |

    Hey guys,
    Could someone send me those two dll’s too? Can’t find them anywhere

    Thanks in advance!

    Reply

  • Avatar

    Cold

    |

    Hi
    Can you do it for Visual Basic 6.0

    I will pay 50$ for that.

    Reply

Leave a comment