PHP 코드가 작동하지 않아서 액세스 토큰을 얻지 못했습니다. 클라이언트 ID와 비밀 키에서 실제 클라이언트 ID와 키로 바뀌 었습니다.Instagram PHP 코드에서 액세스 토큰 가져 오기
<?php
$client_id = 'MY CLIENT ID';
$client_secret = 'MY CLIENT SECRET';
$redirect_uri = 'http://localhost/instagram/demo.php';
$scope = 'basic+likes+comments+relationships';
$url = "https://api.instagram.com/oauth/authorize?client_id=$client_id&redirect_uri=$redirect_uri&scope=$scope&response_type=code";
if(!isset($_GET['code']))
{
echo '<a href="'.$url.'">Login With Instagram</a>';
}
else
{
$code = $_GET['code'];
$apiData = array(
'client_id' => $client_id,
'client_secret' => $client_secret,
'grant_type' => 'authorization_code',
'redirect_uri' => $redirect_uri,
'code' => $code
);
$apiHost = 'https://api.instagram.com/oauth/access_token';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiHost);
curl_setopt($ch, CURLOPT_POST, count($apiData));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($apiData));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$jsonData = curl_exec($ch);
curl_close($ch);
var_dump($jsonData);
$user = @json_decode($jsonData);
echo '<pre>';
print_r($user);
exit;
}
?>
위의 코드는 항상 false를 반환합니다. 왜 이것이 작동하지 않는지 알 수 없습니다.
아무나이 코드를 디버그하고 내 코드의 문제점을 알려주십시오.