Unable to get Streaming API pass AuthZ 401 Unauthorize

oauth
filter
streaming
auth
authorization

#1

I am new to using Twitter API. I am trying to get data from the filter endpoint:

https://stream.twitter.com/1.1/statuses/filter.json?

In my play application I have following code (using WS and Iteratee from Scala):

WS.url(twitterURL)
      .sign(OAuthCalculator(play.api.libs.oauth.ConsumerKey("xxx","xxx"), play.api.libs.oauth.RequestToken("xxx","xxxx")))
      .postAndRetrieveStream(postData) {
        _ => postProcessResponseIte();
      }

But for some reason I am getting 401 UnAuthorized response:

HTTP/1.1 401 Authorization Required
cache-control: must-revalidate,no-cache,no-store
connection: close
content-length: 267
content-type: text/html
date: Wed, 06 Jan 2016 22:50:50 GMT
server: tsa
www-authenticate: OAuth realm="Firehose"
x-connection-hash: 0ae753e0b97ca45c5a3dd4f1167600bf

<html>\n<head>\n<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>\n<title>Error 401 Unauthorized</title>
</head>
<body>
<h2>HTTP ERROR: 401</h2>
<p>Problem accessing '/1.1/statuses/filter.json?'. Reason:
<pre>    Unauthorized</pre>
</body>
</html>

I have checked my machine time and it seems to be matching with what is in the response. Not sure how can I get around this.

Any help is much helpful. Thanks in advance !!


#2

Below is --verbose output for CURL

* Hostname was NOT found in DNS cache
*   Trying 199.16.156.217...
* Connected to stream.twitter.com (127.0.0.1) port 443 (#0)
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
* Server certificate: stream.twitter.com
* Server certificate: VeriSign Class 3 Secure Server CA - G3
> POST /1.1/statuses/filter.json HTTP/1.1
> Host: stream.twitter.com
> Accept: */*
> Content-Type:application/json; charset=utf-8
> Authorization:OAuth oauth_consumer_key="ilBC7m21KNvk7si7QoY5ZU0TL", oauth_token="4572253935-0AJMQm3orucP2dvN1q9mBqkrqLF9wWMBbbcAlcg", oauth_signature_method="HMAC-SHA1", oauth_signature="dAvjaaZu2j2yyX75WtpQuDkzDsc%3D", oauth_timestamp="1452188942", oauth_nonce="nzvmgDQ3lM%2FJjzz5P4yhTA%3D%3D", oauth_version="1.0"
> User-Agent:AHC/1.0
> Content-Length: 1392
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
HTTP/1.1 100 Continue

< HTTP/1.1 401 Authorization Required
HTTP/1.1 401 Authorization Required
< cache-control: must-revalidate,no-cache,no-store
cache-control: must-revalidate,no-cache,no-store
< connection: close
connection: close
< content-length: 266
content-length: 266
< content-type: text/html
content-type: text/html
< date: Thu, 07 Jan 2016 17:56:36 GMT
date: Thu, 07 Jan 2016 17:56:36 GMT
* Server tsa is not blacklisted
< server: tsa
server: tsa
< www-authenticate: OAuth realm="Firehose"
www-authenticate: OAuth realm="Firehose"
< x-connection-hash: 7f6bd53304eca0729e3166846713c962
x-connection-hash: 7f6bd53304eca0729e3166846713c962

<
<html>\n<head>\n<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>\n<title>Error 401 Unauthorized</title>
</head>
<body>
<h2>HTTP ERROR: 401</h2>
<p>Problem accessing '/1.1/statuses/filter.json'. Reason:
<pre>    Unauthorized</pre>
</body>
</html>
* Closing connection 0