I have an issue on generating my bearer token, in java. I've got this:
Code: Select all
09:41:19.410 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "<error><code>400</code><message>invalid_access_token</message><description>Access token is invalid</description>[\n]
Here is the code i use:
Code: Select all
public static String getBearerToken() throws URISyntaxException, IOException {
String basicAuth = getBase64(consummerKey, consummerSecretKey);
String bearerToken = null;
HttpClient httpClient = HttpClients.custom()
.setDefaultRequestConfig(RequestConfig.custom()
.setCookieSpec(CookieSpecs.STANDARD).build())
.build();
URIBuilder uriBuilder = new URIBuilder("https://ops.epo.org/3.2/acesstoken");
ArrayList<NameValuePair> queryParameters;
queryParameters = new ArrayList<>();
queryParameters.add(new BasicNameValuePair("grant_type", "client_credentials"));
uriBuilder.addParameters(queryParameters);
HttpPost httpPost = new HttpPost(uriBuilder.build());
httpPost.setHeader("Authorization", basicAuth);
httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
HttpResponse response = httpClient.execute(httpPost);
HttpEntity entity = response.getEntity();
if (null != entity) {
bearerToken = EntityUtils.toString(entity, "UTF-8");
}
return bearerToken;
}
Raphaël