Access token, Refresht token 갱신 질문

아래와 같은 스크립트를 구성햇는데요…
어디가 잘 못 인지 모르겠습니다.

재 갱신을 위한 코드도 확인 햇습니다만…
{grant_type=refresh_token&client_id=".$CLIENT_ID."&refresh_token=".$result[refresh_token]}
어디에서 잘 못이 되었는지 모르겠군요,

$CLIENT_ID = $kakao[‘rest_api_key’];
$REDIRECT_URI = $kakao[‘callback_url’];
$authorize_code = $_GET[“code”];

// POST the code to get an access token
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,“https://kauth.kakao.com/oauth/token”);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, “grant_type=authorization_code&client_id=”.$CLIENT_ID."&redirect_uri=".$REDIRECT_URI."&code=".$authorize_code."");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec ($ch);
curl_close ($ch);

echo "res 1 : ". $result;
$result = json_decode($result, true);
$access_token = $result[‘access_token’];

if($access_token){
// POST the access token to get user info
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,“https://kapi.kakao.com/v1/user/me”);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer '.$access_token));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec ($ch);
echo " val 1 : “. $response;
$response = json_decode($response, true);
curl_close ($ch);
} else {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,“https://kauth.kakao.com/oauth/token”);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, “grant_type=refresh_token&client_id=”.$CLIENT_ID.”&refresh_token=".$result[refresh_token]."");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result2 = curl_exec ($ch);
curl_close ($ch);

echo" res 2 : ". $result2;

// POST the access token to get user info
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://kapi.kakao.com/v1/user/me");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Bearer '.$result2[access_token]));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec ($ch);
echo " val 2 : ". $response; 
$response =  json_decode($response, true);
curl_close ($ch);

}

– 아래 결과 값 –

res 1 : {“error”:“invalid_client”,“error_description”:“Bad client credentials”}
res 2 : {“error”:“invalid_client”,“error_description”:“Bad client credentials”}
val 2 : {“msg”:“this access token does not exist”,“code”:-401}

@fokfung
현재 상태로는 되어야 할거 같은데요.
다시 한 번 해보시고 덧글 달아주세요.

자문자답

데이터베이스에서 불러오는 소스 오류가 있었네요;
정상 동작합니다.

1개의 좋아요