我需要根据某些hashtag过滤器阅读推文,所以我尝试了使用java hbc客户端的Twitter的流式api。首先,我尝试运行项目提供的示例代码,以便了解它是如何工作的。
所以我:
但每次我用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源代码,连接对象的连接(HttpUriRequest请求)功能似乎引发了异常(请参阅:hbc-主/ SRC /主/ JAVA / COM /叽叽喳喳/ HBC / HttpClient的/连接)
httpclient异常的Apache文档并没有给出如何处理这个错误的大量线索,我想知道是否有我在这里缺少的东西,一个变化在Twitter的流媒体API中阻止我的代码运行,任何事情......
感谢您提供任何帮助或建议!
Ps 1:只是为了信息,连接(HttpUriRequest请求)是
Ps 2:我的问题可能类似于尚未解决的问题:/ questions / 26363005 / twitter-streaming-w-status-code-401
答案 0 :(得分:1)
我给出答案太晚了,但可能对其他人有用。实际上,如果您的网络配置为使用任何类型的代理,这个问题似乎是由于缺少代理主机和端口的配置。如果您可以浏览代码并设置网络的代理主机和端口,这个问题将得到解决。
P.S:我发现twitter流式传输api非常简单易用,但如果您使用的是配置了像工作场所等代理的网络,请不要忘记配置代理设置。_configurationBuilder是twitter4j.conf.ConfigurationBuilder的类型 _configurationBuilder.setHttpProxyHost("你代理主机"); _configurationBuilder.setHttpProxyPort(您的代理端口号);
如果你错过了,你会在收听消息时收到一些twitterException,并且在谷歌搜索时也不会获得任何信息。