使用Kafka,我试图将数据从Twitter传输到Java,但是当我运行该程序时,出现此错误:
[hosebird-client-io-thread-0] WARN com.twitter.hbc.httpclient.ClientBase - Hosebird-Client-01 IOException caught when establishing connection to https://stream.twitter.com/1.1/statuses/filter.json?delimited=length&stall_warnings=true
[hosebird-client-io-thread-0] WARN com.twitter.hbc.httpclient.ClientBase - Hosebird-Client-01 failed to establish connection properly
[hosebird-client-io-thread-0] INFO com.twitter.hbc.httpclient.ClientBase - Hosebird-Client-01 Done processing, preparing to close connection
<dependency>
<groupId>com.twitter</groupId>
<artifactId>hbc-core</artifactId>
<version>2.2.0</version>
</dependency>
$ curl -I https://stream.twitter.com
HTTP/1.1 404 Not Found
content-length: 0
date: Wed, 26 Jun 2019 13:28:19 GMT
server: tsa_a
set-cookie: personalization_id="v1_HSs6Yj5MLa8Ct13KsRWj3A=="; Max-Age=63072000; Expires=Fri, 25 Jun 2021 13:28:19 GMT; Path=/; Domain=.twitter.com
set-cookie: guest_id=v1%3A156155569958747022; Max-Age=63072000; Expires=Fri, 25 Jun 2021 13:28:19 GMT; Path=/; Domain=.twitter.com
strict-transport-security: max-age=631138519
x-connection-hash: 567cd8537e0e96252c2175e59d752883
x-response-time: 2
这是代码段:
public void run(){
// Setting blocking queues
BlockingQueue<String> msgQueue = new LinkedBlockingQueue<String>(1000);
// create a twitter client
Client client = createTwitterClient(msgQueue);
// Establish a connection.
client.connect();
// looping thru code
// etc
}
public Client createTwitterClient(BlockingQueue<String> msgQueue){
// Declared the keys and tokens
// Host to connect to, the endpoint, and authentication (basic auth or oauth) */
Hosts hosebirdHosts = new HttpHosts(Constants.STREAM_HOST); <- this guy
StatusesFilterEndpoint hosebirdEndpoint = new StatusesFilterEndpoint();
// rest of the code for ClientBuilder and Client
}
其中Constants.STREAM_HOST为:
public static final String STREAM_HOST = "https://stream.twitter.com";
我希望建立连接并能够接收推文。 STREAM_HOST没有建立连接的原因是什么?
答案 0 :(得分:0)
感谢那些阅读我的问题的人。
这似乎是由于我的笔记本电脑防火墙设置导致的。我在另一台安全性较低的笔记本电脑上尝试了完全相同的代码,它的工作原理就像一个魅力。将需要与管理员一起弄清楚。