Streaming API works with GET, fails with POST


#1

Hi all,

I am trying to consume the streaming api endpoint “https://stream.twitter.com/1.1/statuses/filter.json”. I am passing a track parameter

along with it.

The Get request is as shown below and works perfectly.

https://stream.twitter.com/1.1/statuses/filter.json?oauth_consumer_key=MyConsumerKey&oauth_nonce=MyNonce&oauth_signature_method=HMAC-

SHA1&oauth_timestamp=1400104784&oauth_token=MyToken&oauth_version=1.0&track=twitter

I wanted to consume this endpoint as a POST and have tried the below three cases without success.

  1. oAuth and track parameters as part of the URL
  2. oAuth parameters as part of the URL and track parameter as part of the postBody content
  3. oAuth and track parameters as part of the postBody content

I made sure I sent the content was “application/x-www-form-urlencoded” formatted as shown below
HttpContent content = new StringContent(postBody, Encoding.ASCII, “application/x-www-form-urlencoded”);

case 1) Details - oAuth and track parameters as part of the URL

POST Url:
https://stream.twitter.com/1.1/statuses/filter.json?oauth_consumer_key=MyConsumerKey&oauth_nonce=MyNonce&oauth_signature_method=HMAC-

SHA1&oauth_timestamp=1400104784&oauth_token=MyToken&oauth_version=1.0&track=twitter

   var postBody = string.Format("track={0}", Uri.EscapeDataString("twitter"));
   HttpContent content = new StringContent(postBody, Encoding.ASCII, "application/x-www-form-urlencoded");

Status Code : 401
ReasonPhrase : Authorization Required

case 2) oAuth parameters as part of the URL and track parameter as part of the postBody content

POST Url:
https://stream.twitter.com/1.1/statuses/filter.json?oauth_consumer_key=MyConsumerKey&oauth_nonce=MyNonce&oauth_signature_method=HMAC-

SHA1&oauth_timestamp=1400104784&oauth_token=MyToken&oauth_version=1.0

   var postBody = string.Format("track={0}", Uri.EscapeDataString("twitter"));
   HttpContent content = new StringContent(postBody, Encoding.ASCII, "application/x-www-form-urlencoded");

Status Code : 401
ReasonPhrase : Authorization Required

case 3) oAuth and track parameters as part of the postBody content

Status Code : 401
ReasonPhrase : Authorization Required

I needed to know what should be the resourceURL, Authorization Header and the postBody content for the post streaming API.

Please assist.

Thanks