Hello,
I am attempting to create an Android application that will use the Twitter Streaming API. I want to make it clear that I don’t want to use an external library. With that being said here is the code I currently have:
HttpClient streamClient = null;
try{
streamClient = new DefaultHttpClient();
HostnameVerifier verifier = org.apache.http.conn.ssl.SSLSocketFactory.STRICT_HOSTNAME_VERIFIER;
SchemeRegistry registry = new SchemeRegistry();
org.apache.http.conn.ssl.SSLSocketFactory socketFactory = org.apache.http.conn.ssl.SSLSocketFactory.getSocketFactory();
socketFactory.setHostnameVerifier((X509HostnameVerifier)verifier);
registry.register(new Scheme("https", socketFactory, 443));
SingleClientConnManager cm = new SingleClientConnManager(streamClient.getParams(), registry);
HttpClient defaultHttpClient = new DefaultHttpClient(cm, streamClient.getParams());
HttpGet request = new HttpGet("https://stream.twitter.com/1.1/statuses/filter.json?track=London");
request.setHeader("User-Agent", "My App v 1.0");
request.setHeader("Accept", "*/*");
request.setHeader("Content-Type", "application/x-www-form-urlencoded");
String consumerKey = "***";
String consumerSecret = "***";
String accessToken = "***";
String accessTokenSecret = "***";
oauth.signpost.OAuthConsumer consumer = new CommonsHttpOAuthConsumer(consumerKey, consumerSecret);
consumer.setTokenWithSecret(accessToken, accessTokenSecret);
consumer.sign(request);
HttpResponse response = defaultHttpClient.execute(request);
Scanner in = new Scanner(response.getEntity().getContent());
String str = "";
while (in.hasNext()){
str += in.nextLine() + "\n";
}
System.out.println("JSON data: " + str);
statuses.add(str);
}
catch (Exception ex){
System.out.println("Error: " + ex.getMessage());
}
I want to make it clear that all my secrets and token values are correct.
With that being said, when I run my code, I get the error/exception “No peer certificate”. How can I fix this?