使用Flink连接到Twitter源时发生IOException

时间:2017-11-20 07:44:43

标签: java twitter apache-flink

这是我的Java代码:

import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.connectors.twitter.TwitterSource;

import java.util.Properties;

public class FilterEnglishWords {
    public static void main(String[] args) throws Exception {
        final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        Properties props = new Properties();
        props.setProperty(TwitterSource.CONSUMER_KEY, "xxx");
        props.setProperty(TwitterSource.CONSUMER_SECRET, "xxx");
        props.setProperty(TwitterSource.TOKEN, "xxx");
        props.setProperty(TwitterSource.TOKEN_SECRET, "xxx");

        env.addSource(new TwitterSource(props))
                .print();
        env.execute();
    }
}

当我运行应用程序时,我收到以下错误。

WARN  com.twitter.hbc.httpclient.ClientBase     - flink-twitter-source failed to establish connection properly
INFO  com.twitter.hbc.httpclient.ClientBase     - flink-twitter-source Done processing, preparing to close connection
INFO  com.twitter.hbc.httpclient.ClientBase     - flink-twitter-source Establishing a connection
WARN  com.twitter.hbc.httpclient.ClientBase     - flink-twitter-source IOException caught when establishing connection to https://stream.twitter.com/1.1/statuses/sample.json

知道这可能是什么以及如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

这是因为连接问题。我工作的公司阻止了通过终端的网络访问,这阻止了程序连接到Twitter。

通过其他网络连接解决了这个问题。