Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing Apache HttpClient with Twitter Streaming API response issues
    text
    copied!<p>So I decided to give the Twitter Streaming api a shot so I went up to the twitter dev page and created a test application generated my oAuth tokens and all then I tried it using the curl command in the terminal and I got the stream coming in just fine, but then I decided to try to write a little piece of java snippet to sort of do the same thing then its where I faced the problem.</p> <p>Below here is my code, I have removed my tokens and authorization codes by writing in * instead of the real ones.</p> <pre><code>public final static void main(String[] args) throws Exception { HttpClient httpclient = new DefaultHttpClient(); try { HttpPost post = new HttpPost( "https://stream.twitter.com/1/statuses/sample.json"); final String header = "OAuth oauth_consumer_key=\"********\", oauth_nonce=\"*******", oauth_signature=\"**************", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"1339160825\", oauth_token=\"*********", oauth_version=\"1.0\""; final String headerTitle = "Authorization"; post.addHeader(headerTitle, header); ResponseHandler&lt;String&gt; responseHandler = new BasicResponseHandler(); String responseBody = httpclient.execute(post, responseHandler); System.out.println("----------------------------------------"); System.out.println(responseBody); System.out.println("----------------------------------------"); } catch (HttpResponseException e) { System.out.println("Reponse status code: " + e.getStatusCode() + "\n"); e.printStackTrace(); httpclient.getConnectionManager().shutdown(); } } </code></pre> <p>I have also removed the import lines.</p> <p>I keep getting a 401 response, might be something that I'm doing wrong with the headers.</p> <p>Thank you in advance.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload