duanpa1980 2016-12-09 22:56
浏览 73
已采纳

Instagram API访问令牌请求失败

I seen answers for this in other posts but they are quite outdated and I know IG has updated their api since.

I followed their developer documentation but can not seem to make a request from my 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

The above code is how I am making my request but I get the following error.

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

I have disabled implicit oAuth, the app set up is pretty basic, with all the settings going to my personal site for the time being as the app is in sandbox mode anyway.

  • 写回答

2条回答 默认 最新

  • dongzhong5573 2016-12-14 15:30
    关注

    Turns out, I just had to logout of my Instagram account each time I wanted to request a new token.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?