I'm trying to acces the Stackexchange API via OAuth 2.0 implicit flow in a simple java Desktop application.
I already got an non_expiry
acces_token
via URL.
I'm not into OAuth and everything I've tried so far didn't get me any further. Here's what I got so far:
private static final String bearerToken = "foobarbaz"; // acces_token
private static void useBearerToken(String bearerToken, String url_str) throws IOException {
BufferedReader reader = null;
URL url = new URL(url_str);
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setRequestProperty("Authorization", "Bearer" + bearerToken);
connection.setDoOutput(true);
connection.setRequestMethod("GET");
reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line = null;
StringWriter out = new StringWriter(connection.getContentLength() > 0 ? connection.getContentLength() : 2048);
while ((line = reader.readLine()) != null) {
out.append(line);
}
String response = out.toString();
System.out.println(response);
}
public static void main(String[] args) throws IOException {
useBearerToken(bearerToken,"https://api.stackexchange.com/2.2/posts/4308554?site=stackoverflow" );
}
I get following exception:
Exception in thread "main" javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
What am I missing? I also registered my application. Client side flow enabled. Do I have to pass my Client ID or key somewhere?