I’ve been getting 401 while using the streaming API trying to authenticate using OAuth ever since the OAuth tool went down and came back up again. My code was working before and I havent changed anything in it. Should I be changing some request parameters?
This is my code:
public static final String AUTHORIZE_URL = “https://api.twitter.com/oauth/authorize”;
public static final String REQUEST_TOKEN_URL = “https://api.twitter.com/oauth/request_token”;
public static final String ACCESS_TOKEN_URL = “https://api.twitter.com/oauth/access_token”;
HttpClient httpClient = new DefaultHttpClient();
httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, new Integer(Settings.HTTP_CONNECTION_TIMEOUT));
OAuthConsumer consumer = new CommonsHttpOAuthConsumer(OAuthUtils.CONSUMER_KEY,OAuthUtils.CONSUMER_SECRET);
consumer.setTokenWithSecret(OAuthToken.getAccessToken(),OAuthToken.getAccessSecret());
List params = new ArrayList();
params.add(CreateNameValuePair(“track”, “twitter”));
baseUrl = “https://stream.twitter.com/1.1/statuses/filter.json”;
HttpPost httppost = new HttpPost(baseUrl);
httppost.setEntity(new UrlEncodedFormEntity(params, “UTF-8”));
consumer.sign(httppost);
HttpResponse response = httpClient.execute(httppost);
Variable response is
HTTP/1.1 401 Authorization Required [Cache-Control: must-revalidate,no-cache,no-store, connection: close, content-length: 266, Content-Type: text/html, date: Fri, 03 Oct 2014 15:56:01 UTC, server: tsa, WWW-Authenticate: OAuth realm="Firehose", x-connection-hash: 5b928faac0eba33942e0166100cf1dd4]
Same code worked before.
Any help will be appreciated. Thanks!