private static final String PROFILE_URL = "https://graph.facebook.com/me?%s&fields=first_name,last_name,email,birthday,gender,bio,name,relationship_status";
private String getProfile(String code, String accessToken) throws Exception {
StringBuilder sb = new StringBuilder();
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet getRequest = new HttpGet(String.format(PROFILE_URL, accessToken));
getRequest.addHeader("oauth2_access_token", code);
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 getFacebookProfile()", e);
}
return sb.length() > 0 ? JsonUtils.getJsonString(JSONValue.parse(sb.toString())) : "{}";
}
private String getProfile(String code, String accessToken) throws Exception {
StringBuilder sb = new StringBuilder();
try {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet getRequest = new HttpGet(String.format(PROFILE_URL, accessToken));
getRequest.addHeader("oauth2_access_token", code);
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 getFacebookProfile()", e);
}
return sb.length() > 0 ? JsonUtils.getJsonString(JSONValue.parse(sb.toString())) : "{}";
}
No comments:
Post a Comment