Twitter4j interfaces and class structure

好久不见. 提交于 2019-12-11 16:22:10

问题


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.

  1. Could someone show me the structure of this library so I can figure out how to use it?
  2. What objects can I instantiate to use methods from the trending, User, and timeline interfaces?

回答1:


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.

Twitter twitter = new TwitterFactory().getInstance();

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 the twitter reference. It looks like TimelineMethods are what you want, specifically the getUserTimeline method that takes a userId as a parameter, or the one that takes a user's screenName.

Also check out what's available in the TrendsMethods and SearchMethods interfaces (both also implemented by the TwitterImpl class).



来源:https://stackoverflow.com/questions/12336288/twitter4j-interfaces-and-class-structure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!