【发布时间】:2014-12-21 13:43:24
【问题描述】:
我需要根据某些标签过滤器阅读推文,所以我用 java hbc 客户端尝试了 Twitter 的流 api。首先,我尝试运行项目提供的示例代码,以了解它是如何工作的。
所以我:
- 在 twitter 上声明了一个应用程序 + 生成了我的访问密钥、令牌和 秘密
- 从(https://github.com/twitter/hbc)下载项目包
- 通过填写 pom.xml 文件中的 TODO 字段来配置示例项目 hbc-example 我的应用的密钥、令牌和机密 (https://github.com/twitter/hbc/blob/master/hbc-example)
- 将示例项目 hbc-example 配置为在依赖项中同时使用 hbc-core 和 hbc-twitter4j 以避免依赖项错误
但是每次我用 maven 运行 hbc-example 我似乎总是得到:
(...)
[hosebird-client-io-thread-0] INFO com.twitter.hbc.httpclient.ClientBase - hoseb
ird-client-0 Establishing a connection
[hosebird-client-io-thread-0] WARN com.twitter.hbc.httpclient.ClientBase - hoseb
ird-client-0 IOException caught when establishing connection to https://stream.t
witter.com/1.1/statuses/filter.json?delimited=length&stall_warnings=true
[hosebird-client-io-thread-0] WARN com.twitter.hbc.httpclient.ClientBase - hoseb
ird-client-0 failed to establish connection properly
[hosebird-client-io-thread-0] INFO com.twitter.hbc.httpclient.ClientBase - hoseb
ird-client-0 Done processing, preparing to close connection
[hosebird-client-io-thread-0] INFO com.twitter.hbc.httpclient.ClientBase - hoseb
ird-client-0 Establishing a connection
[hosebird-client-io-thread-0] WARN com.twitter.hbc.httpclient.ClientBase - hoseb
ird-client-0 IOException caught when establishing connection to https://stream.t
witter.com/1.1/statuses/filter.json?delimited=length&stall_warnings=true
[hosebird-client-io-thread-0] WARN com.twitter.hbc.httpclient.ClientBase - hoseb
ird-client-0 failed to establish connection properly
[hosebird-client-io-thread-0] INFO com.twitter.hbc.httpclient.ClientBase - hoseb
ird-client-0 Done processing, preparing to close connection
[hosebird-client-io-thread-0] INFO com.twitter.hbc.httpclient.ClientBase - hoseb
ird-client-0 Establishing a connection
[hosebird-client-io-thread-0] WARN com.twitter.hbc.httpclient.ClientBase - hoseb
ird-client-0 IOException caught when establishing connection to https://stream.t
witter.com/1.1/statuses/filter.json?delimited=length&stall_warnings=true
(...)
当我使用 FilterStreamSample 类作为具有“main”函数的类运行 hbc-example 时也会发生这种情况
查看 hbc-core 源,异常似乎是由 Connection 对象的 connect(HttpUriRequest request) 函数引发的(参见:hbc-master/src/主/java/com/twitter/hbc/httpclient/Connection)
httpclient 异常的 Apache 文档并没有提供太多关于如何处理此错误的线索,我想知道这里是否遗漏了什么,Twitter 的流 API 的更改阻止了我的代码运行,等等...
感谢您的任何帮助或建议!
Ps 1 : 仅供参考,connect(HttpUriRequest request) 是
- 在ClientBase.establishConnection(Connection conn, HttpUriRequest request)中调用
- 在ClientBase.run()中调用
- 在 BasicClient.connect() 中调用
- 由 main 调用
Ps 2:我的问题可能类似于这个尚未解决的问题:/questions/26363005/twitter-streaming-w-status-code-401
【问题讨论】:
标签: java twitter httpclient twitter-oauth twitter-streaming-api