AP Computer Science :: Projects :: Twitter
Due: Feb 27
The Java API (application program interface) is a set of classes for building software applications in Java. Many companies provide an API for their programs to allow third-party developers to create programs on top of the company's program. For this project, we are going to use an API to access Twitter.
Part 1: Connecting and Tweeting
For this project we will be using the Twitter4J API. You can go to the website to download or view the JavaDoc.
- Unzip this file to start your project.
- In BlueJ, go to Tools>Preferences and select the "Library" tab.
- Add the lib\twitter4j-core-4.0.2.jar file from the project folder.
- After closing BlueJ your project should compile.
- Go to Twitter and sign up for an account. You will need to add an email address and mobile phone number. You can delete this account after the project is over if you'd like.
- Go to Twitter Apps and choose "Create New App."
- Enter whatever you want for the app information and agree to the Developer Agreement.
- Edit the .properties file in the project folder to include your project's API keys and token.
- In the setUpAndTweet() method, make a tweet using the twitter.updateStatus() method.
Part 2: Most Common Word
You will access the last 2,000 tweets of a person's twitter handle (this can be your own, someone you know, or a public figure) and determine the most common word they use. To do this, you will need to grab a user's most recent 2,000 tweets, store individual words in a data structure of your choice, and then write an algorithm to determine the most common term. Since it would not be interesting to count "the", "a", "and", or similarly all-too common words you need to remove those too-common words. Fortunately, those too-common words are in the file commonWords.txt. Remove those too-common words from the tweeter's list of words before determining the tweeter's most commonly used word. Note: you will need multiple data structures for this assignment – at least one must be an ArrayList.
Once you have all the tweets in a list you need to determine the most common word. You may also want to remove any words starting with the @ symbol since that’s not always interesting. You might find yourself wanting to do things like remove punctuation and sort words.
Please enter a Twitter handle, do not include the @symbol --> realDonaldTrump Count = 317 out of the last 1978 tweets. The most common word from @realDonaldTrump is: trump Please enter a Twitter handle, do not include the @ symbol --> BernieSanders Count = 179 out of the last 1964 tweets. The most common word from @BernieSanders is: people Please enter a Twitter handle, do not include the @ symbol --> NASA Count = 264 out of the last 1996 tweets. The most common word from @NASA is: #yearinspace Please enter a Twitter handle, do not include the @ symbol --> BillNye Count = 203 out of the last 1579 tweets. The most common word from @BillNye is: science Please enter a Twitter handle, do not include the @ symbol --> yhscs Count = 71 out of the last 406 tweets. The most common word from @yhscs is: computer
Part 3: Investigation
- Filter your timeline (all the tweets from people you follow) to avoid a particular term. For instance, if you are an Android fan, you could filter out all tweets with Apple in them.
- Count the number of tweets originating from your zip code that contain the word "flu."
- Send tweets every hour to your friend on his/her birthday. Use a timer, of course.
- Check out the sample code that searches for tweets in the last week about the Miami Dolphins near Arlington, Virginia.