Tag Archives: OAuth

Fight with threads (I won)

4 May

Today I made some major improvements on Twitthere. In short, I completed the OAuth authorisation cycle including serializing the user credentials and token data to a local file. This may seem simple but it is hard to get it right and to keep it that way. I must confess, I haven’t caught all exceptions sufficiently but I was so happy it all worked I’m taking the rest of the evening off 😉 Those exceptions will stay there and wait for me to solve them.

Anyway, it took me a lot of puzzling to get it all right. I’ve been working non-stop from 2 o’clock today until now (half past 10 in the evening) to get it to work. The thing that bugged me most was the loading screen I came up with to keep the user attracted to the program. The API calls to get tokens and swap the request token for an access token take some time, and the GUI would freeze while doing that. Everyone knows that’s a pain in the ass for the user, who has to stare at a frozen GUI for a couple of seconds. So, I threaded the API calls to keep the GUI interactive during the requests and at first it wouldn’t work. Finally, after some thorough puzzling and a lot of trial-and-error, it worked. The loading screen now shows a small animation with ticking dots (like ‘Loading…’, and the amount of dots changes) and it has an animated GIF showing a ‘loading’ animation. You can’t imagine how glad I was I came to the last panel, the ConfirmPanel, which shows that the user can finally start using Twitthere (so weird to put so much effort in the code to just let the user open their profile). For a small development peek, to see how and in what IDE I work, check the images below.

Of course I also updated the javadoc, so have a look at my new panels!

— Léon

New logic

2 May

After giving the current (infra)structure some thought, I came to the conclusion that it didn’t suit my needs. The TwitterUser class was too complex and the OAuth authorization cycle should actually be a class by itself, so I extracted all OAuth functionality from the TwitterUser class to the newly created OAuth class. The TwitterUser class is still present, because we need it later on to make some custom methods (like asynchronous API calls) and it also stores its own access token and access token secret. Furthermore I added a constructor which makes it possible to create a TwitterUser with a token ID and token secret specified (received from the file by FileIO). The instance then automatically assigns an access token to itself using the OAuth class and the two parameters.

The basics for user authorization and registration are now complete. Twitthere can now authorize Twitter users by using OAuth and can serialize the token the users receive from the authorization cycle to a file. I hope that maybe today or else tomorrow I can start on creating the first JFrame containing the login screen.

Of course I’ll keep you posted, and check out the project summary at http://sourceforge.net/projects/twitthere if you are interested in the project!

— Léon

Version 0.1 (or actually online

2 May

I just posted the very first version of the documentation on the web for you to view/download.

If you are interested, you can download the Javadoc here:


This version includes the first two classes I will be using, TwitterUser and FileIO. TwitterUser is responsible for all Twitter-related actions, like for example logging in and performing the OAuth dance on first use (getting access tokens from request tokens). FileIO (not finished yet) will then serialize these to a file for later use. It also recovers them from the specified file. I hope you enjoy seeing the very first Twitthere code in action and any comments are welcome of course!

If you’d like access to the SVN repository to check out the source code, please contact me.

— Léon