0

I try to make a stream connection to Twitter using spring-social-twitter, but when I try to make a request I've got 401 unauthorized.

spring-social-twitter is trying to connect to https://stream.twitter.com/1.1/statuses/filter.json. When I debug it and try to get response.getBody() I've got HttpRetryException with detailed message: cannot retry due to server authentication, in streaming mode.

I have proper authorization for app but I have no authorization for access token, since I don't need it here. I use 1.1.0.RELEASE version.

I will be very glad for your help!

This is my call for stream:

final Stream stream = twitter.streamingOperations().filter(keywords, listeners);

This is my simple listener class:

private class TwitterStreamListener implements StreamListener {

    private static final Logger LOGGER = LoggerFactory.getLogger(TwitterStreamListener.class);

    @Override
    public void onTweet(Tweet tweet) {
        LOGGER.info("onTweet");
    }

    @Override
    public void onDelete(StreamDeleteEvent deleteEvent) {
        LOGGER.info("onDelete");
    }

    @Override
    public void onLimit(int numberOfLimitedTweets) {
        LOGGER.info("onLimit");
    }

    @Override
    public void onWarning(StreamWarningEvent warningEvent) {
        LOGGER.info("onWarning");
    }
}
Ziemo
  • 941
  • 8
  • 27

1 Answers1

0

Finally I found the answer. I posted it here, so maybe it will help others with the same issue.

I figured out that Twitter blocked my app to make a streaming connection before I connect myself, as a browser client to the app. So I needed to received access token of a user to make a stream connection.

Earlier when I tried to connect - nothing happened.. It was because I had wrong Callback URL in my app settings (on twitter's page).

When I changed Callback URL to http://127.0.0.1 (it could be any kind of valid URL and your application doesn't need to have the same, but you can't use something like localhost).

After that I could connect my app to my twitter's account which allows me to start streaming connection. After all I don't know why Twitter requires user connection for stream public tweets. It is not required for search REST API.

Ziemo
  • 941
  • 8
  • 27