토큰은 정상적으로 처리가 되는데
사용자 정보 요청시에만 계속 500에러가 떨어집니다. (https://kapi.kakao.com/v1/user/me)
StringBuffer rtnData = new StringBuffer();
String urlStr = "https://kauth.kakao.com/oauth/token";
String paramStr = "grant_type=" + param.getString("grant_type") + "&client_id=" + param.getString("client_id");
paramStr += "&redirect_uri=" + param.getString("redirect_uri");
paramStr += "&code=" + param.getString("code");
log.error("URL : " + paramStr.toString());
URL url = new URL(urlStr);
URLConnection httpConnection = url.openConnection();
httpConnection.setUseCaches(false);
httpConnection.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(httpConnection.getOutputStream());
wr.write(paramStr);
wr.flush();
BufferedReader in = new BufferedReader(new InputStreamReader(httpConnection.getInputStream(), "UTF-8"));
String line = null;
while ((line = in.readLine()) != null) {
rtnData.append(line);
}
in.close();
// map으로 정보 만듬
Map m = HttpUtil.jsonToMap(rtnData.toString());
// access token 정보로 사용자 정보 가져오기
// rest api 양식
/*
GET/POST /v1/user/me HTTP/1.1
Host: kapi.kakao.com
Authorization: Bearer {access_token}
Content-type: application/x-www-form-urlencoded;charset=utf-8
*/
rtnData = new StringBuffer();
url = new URL("https://kapi.kakao.com/v1/user/me");
httpConnection = url.openConnection();
String auth= "Bearer " + (String)m.get("access_token");
httpConnection.setRequestProperty ("Authorization", auth);
httpConnection.setUseCaches(false);
in = new BufferedReader(new InputStreamReader(httpConnection.getInputStream(), "UTF-8"));
line = null;
while ((line = in.readLine()) != null) {
rtnData.append(line);
}
in.close();