Twitter4j接口和类结构 [英] Twitter4j interfaces and class structure

查看:97
本文介绍了Twitter4j接口和类结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

twitter4j软件包对我来说并不清楚。例如,我如何检索包含特定标签的500条推文?我如何在过去一周内声明用户并获取所有推文?例如,我想要以下内容:

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. 有人可以告诉我这个库的结构,以便我可以弄清楚如何使用它吗?

  2. 我可以实例化哪些对象来使用趋势,用户和时间线界面中的方法?


推荐答案

您可以先查看Twitter4J文档中的代码示例。请注意,对于某些示例,您需要在twitter4j.properties中配置OAuth凭据。

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.

基本上,一切都以 Twitter object。

Basically, everything starts with a Twitter object.

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

通过查看javadoc,您可以看到 TwitterImpl 实现了许多不同的接口,所以那里通过 twitter 引用提供了许多很多方法。它看起来像 TimelineMethods 是你想要的,特别是 getUserTimeline userId 作为参数的方法,或者取用户的方法c $ c> screenName

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.

同时查看 TrendsMethods SearchMethods 接口(两者也由 TwitterImpl实现 class)。

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

这篇关于Twitter4j接口和类结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆