Inspiration
We both knew Java. We both also needed an idea, so we searched through a list of APIs to use. I (Langston) also attended the Node.js lecture, which discussed things like JSON. Two APIs caught our eye: the twitter API and a word cloud API. We decided to combine the two.
What it does
First, it authenticates our twitter organization by exchanging keys for an OAUTH2 token. The keys were gained when we registered our twitter app on twitter.com.
Once we have the OATH2 token, we can then use the twitter search API. It sends a POST request to the search API, with the OATH2 token as a header. We then get a JSON file 80 tweets that match the source criteria.
We then had to turn the JSON file into a list of words in the tweets. We did this by extracting the "text" field from the array of tweets in the JSON file. Then, we split each tweet on the space character to create an array of words.
Next, it sanitizes the list of words by removing any instances of the search query, any punctuation, any URLs, or any short words (<3 chars).
It then passes the word list, along with formatting options, as a POST request to the Word Cloud Generator API. The API returns JSON with the URL for the Word Cloud image.
How I built it
We built it with Java and Eclipse. We essentially used the java-json library and a bunch of miscellaneous HTTP classes to send POST requests. Although originally we hard coded the specific POST requests we wanted to do, eventually we generalized the POST request to work with any JSON text and headers. We also used the APIs previously mentioned.
Challenges I ran into
We had an extremely difficult time doing the authentication, and it was the single longest step even though it is the least impressive. We had a hard time figuring out even what strategy we were going to use, much less how we would do it. However, eventually we figured out how to send JSON requests with Java, and we decided on an Application-only approach to the twitter API. We also had to make a hashing mechanism for our keys.
Accomplishments that I'm proud of
I was very proud of getting the Twitter API working, because it was my first time working with HTTP or JSON. Also, it is very cool to be able to get data from a web server like that.
What I learned
We learned a lot about APIs, and JSON (and a little bit of OAUTH 2). Also, we learned how difficult it is to work with raw post requests in Java, so maybe next time it would be better to use Node.js or python.
What's next for Twitter Word Cloud
Switching to a free and more powerful word cloud library, or hosting it on a finished website. If the code was to be public, we would need to encrypt our keys better, because right now they are not secure.
Log in or sign up for Devpost to join the conversation.