문의 시, 사용하시는 개발환경과 디벨로퍼스 앱ID를 알려주세요.
[Around before] 메서드 :com.model2.mvc.service.kakao.impl.KakaoServiceImpl.getAccessToken
[Around before]method에 전달되는 인자 : undefined
authorize_code : undefined
responseCode : 400
[Around after] 타겟 객체return value :
[Around before] 메서드 :com.model2.mvc.service.kakao.impl.KakaoServiceImpl.getUserInfo
[Around before]method에 전달되는 인자 :
java.io.IOException: Server returned HTTP response code: 400 for URL: https://kauth.kakao.com/oauth/token
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at sun.net.www.protocol.http.HttpURLConnection$10.run(HttpURLConnection.java:1964)
자꾸 400 에러에 undifined를 받아옵니다…
$(document).ready(function() {
Kakao.init(‘156ad557ed4df3d2e6fa9905dae81a56’);
// 카카오 로그인 버튼을 생성합니다.
Kakao.Auth.createLoginButton({
container: ‘#kakao-login-btn’,
success: function (authObj) {
debugger;
alert(JSON.stringify(authObj));
console.log(authObj);
window.location.href = “http://localhost:8080/kakao/login?code=” + authObj.code;
},
fail: function (err) {
alert(JSON.stringify(err));
}
});
});
public String getAccessToken (String authorize_code) {
String access_Token = “”;
String refresh_Token = “”;
String reqURL = “카카오계정;
try {
URL url = new URL(reqURL);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
// POST 요청을 위해 기본값이 false인 setDoOutput을 true로
conn.setRequestMethod("POST");
conn.setDoOutput(true);
conn.setRequestProperty("Content-type","application/x-www-form-urlencoded;charset=utf-8");
// POST 요청에 필요로 요구하는 파라미터 스트림을 통해 전송
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(conn.getOutputStream()));
StringBuilder sb = new StringBuilder();
sb.append("grant_type=authorization_code");
sb.append("&client_id=8df753a4b334db7b6d9d4824b176caf5"); //본인이 발급받은 key
sb.append("&redirect_uri=http://localhost:8080/kakao/login"); // 본인이 설정해 놓은 경로
sb.append("&code=" + authorize_code);
System.out.println("authorize_code : " + authorize_code);
bw.write(sb.toString());
bw.flush();
// 결과 코드가 200이라면 성공
int responseCode = conn.getResponseCode();
System.out.println("responseCode : " + responseCode);
ID 1056703 test 입니다!!
kakao.zip (10.7 KB)