액세스토큰까지 잘 받아오는것까지 확인했습니다.
근데
$url = “https://kapi.kakao.com/v2/user/me”;
이 부분에서 호출할때 계속 400을 리턴하네요
혹시 뭐가 문제인지 알려주실수 있으실까요 ?
header(‘Access-Control-Allow-Origin: *’);
$client_id = "9ac94a6089d7fd36cc408a5bd10fa618";
$state = gRequest(“state”);
$code = gRequest(“code”);
$returnUrl = $_REQUEST[“returnUrl”];
$sesReturnUrl = $_SESSION[“sesReturnUrl”];
$ch = curl_init();
$url = 'https://kauth.kakao.com/oauth/token'
.'?grant_type=authorization_code'
.'&client_id='.$client_id // client_id
.'&returnUrl='.urlencode($returnUrl) // redirect_uri
.'&code='.urlencode($code) // get방식으로 받은 code변수의 값
.'&state='.urlencode($state); // 임의의 변수값
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
$token_json = curl_exec($ch);
curl_close($ch);
$data = json_decode($token_json, true);
$token = $data['access_token'];
$header = "Bearer ".$token; // Bearer 다음에 공백 추가
$headers = array();
$headers[] = "Authorization: ".$header;
$ch = curl_init();
$url = "https://kapi.kakao.com/v2/user/me";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec ($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
//echo "status_code:".$status_code."<br>";
curl_close ($ch);
if($response){
var_dump($response);
$response = json_decode($response, true);
$id = $response['id'];
$nickname = $response['properties']['nickname'];
$thumbnail_image = $response['properties']['thumbnail_image'];
$profile_image = $response['properties']['profile_image'];
$kaccount_email = $response['kakao_account']['email'];
}