The twitter4j packages are not clear to me. For instance how would I retrieve 500 tweets containing a certain hashtag? How would I declare a user and get all their tweets in the past week? For example, I would like the following:
User brit = new User("Britney Spears");
List<Tweet> britTweets = brit.getAllTweets(); //assuming this method exists
My problem is I cannot instantiate a User since it is declared abstract! What I see so far is a bunch of interfaces with a set of great functions that I do not know how to use.
- Could someone show me the structure of this library so I can figure out how to use it?
- What objects can I instantiate to use methods from the trending, User, and timeline interfaces?
You can start by looking at the Code Examples in the Twitter4J documentation. Note that for some examples you need to have OAuth credentials configured in twitter4j.properties.
Basically, everything starts with a
Twitter
object.By looking at the javadoc, you can see that the
TwitterImpl
returned by the factory method implements lots of different interfaces, so there are many, many methods available through thetwitter
reference. It looks likeTimelineMethods
are what you want, specifically thegetUserTimeline
method that takes auserId
as a parameter, or the one that takes a user'sscreenName
.Also check out what's available in the
TrendsMethods
andSearchMethods
interfaces (both also implemented by theTwitterImpl
class).