Instagram API 访问令牌请求失败

Instagram API access token request fail

我在其他帖子中看到了这个问题的答案,但它们已经过时了,我知道 IG 已经更新了他们的 api。

我遵循了他们的开发者文档,但似乎无法从我的本地主机发出请求。

$fields = array(
   'client_id'     => 'a2xxxxxxxxxxxxxxxxxxxxxxxxxxxxed',
   'client_secret' => '3bxxxxxxxxxxxxxxxxxxxxxxxxxxxxx8f',
   'grant_type'    => 'authorization_code',
   'redirect_uri'  => 'http://localhost:8000/',
   'code'          => 'code'
);

$url = 'https://api.instagram.com/oauth/access_token';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_POST,true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
$result = curl_exec($ch);
curl_close($ch); 
print $result; //your token

上面的代码是我提出请求的方式,但我收到以下错误。

{"code": 400, "error_type": "OAuthException", "error_message": "Matching code was not found or was already used."}

我已禁用隐式 oAuth,应用程序设置非常基本,所有设置暂时都转到我的个人网站,因为应用程序无论如何都处于沙盒模式。

redirect_uri 应该指向 public URL 地址,而不是 localhost.

事实证明,每次我想请求一个新令牌时,我都必须注销我的 Instagram 帐户。