2016-12-09 179 views
0

我在其他帖子中看到了這個答案,但它們已經過時了,我知道IG自此更新了它的API。Instagram 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,設置應用程序是非常基本的,所有的設置將我的個人網站暫時的,作爲應用在沙盒模式反正。

回答

0

原來,每次我想要申請一個新的令牌時,我只需註銷我的Instagram帳戶。

0

redirect_uri應該指向一個公共URL地址,而不是localhost

+0

'http:// localhost /'是一個真實的URL,但它不是公開的。我允許自己稍微編輯一下你的答案。 – DanFromGermany