Instagram API访问令牌请求失败

时间:2016-12-09 22:56:52

标签: php instagram instagram-api

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

我关注了他们的开发者文档,但似乎无法向我的localhost发出请求。

$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,应用程序设置非常基本,暂时将所有设置都转到我的个人网站,因为应用程序仍处于沙箱模式。

2 个答案:

答案 0 :(得分:0)

redirect_uri应指向公共网址,而不是localhost

答案 1 :(得分:0)

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

相关问题