以下 php 代码不适用于我获取访问令牌在客户端 ID 和密钥中,我已替换为我的真实客户端 ID 和密钥。
<?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 .. 我不明白为什么这不起作用。
有人调试此代码并让我知道我的代码有什么问题吗?