private String getProfile(String authCode, String accessToken) throws Exception {
StringBuilder sb = new StringBuilder();
try {
LOGGER.info("get Google Profile---accessToken---" + accessToken);
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet getRequest = new HttpGet(
"https://www.googleapis.com/plus/v1/people/me"
+ "?access_token=" + accessToken);
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("JSON Object" + sb);
} catch (IOException e) {
LOGGER.error("Error in getGoogleProfile()", e);
}
return sb.length() > 0 ? JsonUtils.getJsonString(JSONValue.parse(sb.toString())) : "{}";
}
StringBuilder sb = new StringBuilder();
try {
LOGGER.info("get Google Profile---accessToken---" + accessToken);
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet getRequest = new HttpGet(
"https://www.googleapis.com/plus/v1/people/me"
+ "?access_token=" + accessToken);
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("JSON Object" + sb);
} catch (IOException e) {
LOGGER.error("Error in getGoogleProfile()", e);
}
return sb.length() > 0 ? JsonUtils.getJsonString(JSONValue.parse(sb.toString())) : "{}";
}
No comments:
Post a Comment