Search code examples
javatwitterapache-flink

IOException while connecting to Twitter source using Flink


Here's my Java code:

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();
    }
}

When I run the application I get the following error.

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

Any idea what this could be and how to resolve this?


Solution

  • This was a because of a connection issue. The company I work for had blocked network access via terminal which was blocking the program to connect to Twitter.

    Connecting via a different network solved the issue.