초보개발자'^'
100
2018-12-12 11:45:04
1
295

kakao restapi 연동 질문드립니다!


kakao rest api 연동을 하고있습니다. 

pom.xml에 아래와 같이 추가하고


<!-- 잭슨 -->
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.9.5</version>
        </dependency>
 
        <!-- httpcore(카카오) -->
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpcore</artifactId>
            <version>4.4.6</version>
        </dependency>
 
        <!-- httpclient(카카오) -->
        <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.5.2</version>
        </dependency>


java에 내용을 추가하였는데

첨부한 사진처럼 뜹니다ㅜ

NameValuePair import도 제가 참고한 코드와는 다르게 import가 되는것도 의문이고

왜이러는지 모르겠습니다

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.HttpClientBuilder;
import org.aspectj.apache.bcel.classfile.annotation.NameValuePair;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

public class kakao_restapi {
    public JsonNode getAccessToken(String autorize_code) {
        final String RequestUrl = "https://kauth.kakao.com/oauth/token";
        final List<NameValuePair> postParams = new ArrayList<NameValuePair>();
        postParams.add(new BasicNameValuePair("grant_type", "authorization_code"));
        postParams.add(new BasicNameValuePair("client_id", "9b572343ecba61a1fd408970ab095c4f"));
        postParams.add(new BasicNameValuePair("redirect_uri", "http://localhost:8130/login"));
        postParams.add(new BasicNameValuePair("code", autorize_code));
        final HttpClient client = HttpClientBuilder.create().build();
        final HttpPost post = new HttpPost(RequestUrl);
        JsonNode returnNode = null;
        try {
            post.setEntity(new UrlEncodedFormEntity(postParams));
            final HttpResponse response = client.execute(post);
            ObjectMapper mapper = new ObjectMapper();
            returnNode = mapper.readTree(response.getEntity().getContent());
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            
        }
        return returnNode;
    }
}


0
0
  • 답변 1

  • 아이러니y
    1k
    2018-12-12 13:56:37

    메이븐으로 라이브러리 땡겨온거맞나염?

    0
  • 로그인을 하시면 답변을 등록할 수 있습니다.