Twitter changed to SSL only for streaming API today

This morning my Twitter data collection program suddenly started failing to connect. I’m using the the excellent twitter4j library for connecting to Twitter.

The error was “Connection Refused” with this response:

TwitterException{exceptionCode=[b5e7486f-24943238 b5e7486f-2494320e], statusCode=-1, retryAfter=-1, rateLimitStatus=null, featureSpecificRateLimitStatus=null, version=2.2.4}

I found out that Twitter has turned on only accepting SSL connections for connecting to streams today. (

I tried setting builder.setUseSSL(true) in Twitter4j, but that didn’t fix the problem. There is a new snapshot build of twitter4j that does fix it (2.2.5-SNAPSHOT). It is available for download from

I’m using Eclipse Helios and Maven and had some trouble working out how to get the SNAPSHOT. In the configuration I have, it picked up the snapshot of twitter4j-stream-2.2.5-SNAPSHOT.jar, but not the twitter4j-core-2.2.5-SNAPSHOT.jar. I tried a few different things to make it get the core snapshot which didn’t work, but then found that disabling the releases in the repository definition worked:

      <name> Repository</name>

Not sure why the twitter4j-stream snapshot was downloaded but not the twitter4j-core without changing the POM. But with this change, my data collection is working again although I’ve missed a few hours of data.

  1. Wow, thanks for taking the time to blog this. I just came across the exact same issue while in midst of migrating 2.1 -> 2.2. So I thought it was something that I’d broken in my API use.

  2. Thank you, thank you, thank you. It was driving me crazy. A couple processing sketches stopped working during this weekend and I checked and rechecked the documentation.

  3. ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setOAuthConsumerKey(“consumerKey”);//pass consumerkey
    cb.setOAuthConsumerSecret(“consumerSecret”);//pass consumersecret
    cb.setOAuthAccessToken(“accessToken”);//pass access token
    cb.setOAuthAccessTokenSecret(“accessTokenSecret”);//pass access token secret
    cb.setStreamBaseURL(“”);//set new url for stream api…

  4. Thanks Prateek,

    I didn’t notice the setStreamBaseURL option when I was looking for ways to fix it. I guess that would have worked without upgrading to the snapshot version.

  5. Hi Brenda,

    yes,setting streaBaseUrl will work,even i tried for my project it was working fine without upgrading to the snapshot version 🙂

  6. Thanks you man, i had this issue for days and i coudn’t solve it !!

  7. Thanks a lot for sharing the solution. Was going nuts trying to fix this.

  8. Hi,

    Thanks to Prateek and Brenda!!

    Even I was trying this for long time with WebSockets and now it got resolved.

    Just adding this:

    cb.setStreamBaseURL(“”);//set new url for stream api…

    is solving the problem, even if we don’t update the latest snapshot from Twitter4j.

    Keep posting.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.