private String getProfile(String authrizationCode, String accessToken) throws Exception {
StringBuilder sb = new StringBuilder();
try {
LOGGER.info("GET MSFT Profile---code---" + code);
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet getRequest = new HttpGet(
"https://apis.live.net/v5.0/me?access_token=" + accessToken + "&format=json");
HttpResponse response = httpClient.execute(getRequest);
if (response.getStatusLine().getStatusCode() != 200) {
throw new Exception("Failed : HTTP error code : " + response.getStatusLine().getStatusCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String output;
while ((output = br.readLine()) != null) {
sb.append(output);
}
br.close();
LOGGER.info("MSFT JSON Object" + sb);
} catch (IOException e) {
LOGGER.error("Error in MSFT getProfile()", e);
}
return sb.length() > 0 ? JsonUtils.getJsonString(JSONValue.parse(sb.toString())) : "{}";
}
Java Microsoft OAuth2 get Access Token
StringBuilder sb = new StringBuilder();
try {
LOGGER.info("GET MSFT Profile---code---" + code);
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet getRequest = new HttpGet(
"https://apis.live.net/v5.0/me?access_token=" + accessToken + "&format=json");
HttpResponse response = httpClient.execute(getRequest);
if (response.getStatusLine().getStatusCode() != 200) {
throw new Exception("Failed : HTTP error code : " + response.getStatusLine().getStatusCode());
}
BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String output;
while ((output = br.readLine()) != null) {
sb.append(output);
}
br.close();
LOGGER.info("MSFT JSON Object" + sb);
} catch (IOException e) {
LOGGER.error("Error in MSFT getProfile()", e);
}
return sb.length() > 0 ? JsonUtils.getJsonString(JSONValue.parse(sb.toString())) : "{}";
}
Java Microsoft OAuth2 get Access Token
No comments:
Post a Comment