Libraries are files of code bundled together to form a program that others can use. They provide an interface, or methods, that we can use. We don’t know the code behind these methods, but we do know what they do. All of these methods together are called the Application Programming Interface, or API. Companies open up API for developers to get data from them and create applications. Our first API for this year is from Twitter, but we are using a library called Twitter4J that lets us use java to connect to the Twitter API.
It’s important to know how to read the documentation so that we can deduce how an API is meant to be used in our code.
Under https://twitter4j.org/en/index.html you can find a section that says “JavaDoc”. You’ll be more familiar with this in the future but this will prove to be a good introduction to Java Documentation.
We’ll be working with version 4.0.7. (Documentation link here) Here we can see, on the left-hand side, that there are MANY classes we could possibly use. This can seem very overwhelming at times, so it’s best if we just focus on one class to start. Let’s use the Twitter4j Package only for now. You can explore the other packages if you’d like.
If you’re not sure whether you’re in the correct spot, click here. Again, we see lots of different classes and a ton of information to try to process.
Here are a couple of the most useful classes, but you are free to use any that you want:
Class Name | Purpose |
Friendship (class) | This class holds information about the relationship between two Twitter users. |
Location (class) | Holds information about the country, URL, and location id(woeid). |
Place (class) | Contains very specific information about the location, or place, of any twitter object. |
Trend (class) | Represents a trending topic, it contains information about the hashtag and tweet volume over the last 24 hours. |
Twitter (class) | The chunkiest class we will use. It contains many methods to perform actions within twitter. Closely connected to TwitterImpl. |
TwitterImpl (class) | Used to create a Twitter class and provides a list of all the methods that we can use for this problem set. |
You’re tasked with creating an algorithm of your choosing. There are many ways to look at this. Perhaps you want to find people that used a certain hashtag. Maybe you want to search for anyone within a certain area or you can search for any posts that use specific keywords. It is completely up to you how you approach this and which direction you take.
The intention is for you to read a bit through documentation, mainly TwitterImpl methods, and see which ones you’d like to use.