Reputation: 459
Hello fellow developers,
I searched everywhere and it seems like this question remain unresolved, some appears to solve this by using proxy servers or changing their IP address, which didn't work in my case. Since Instagram doesn't have an official PHP or JavaScript SDK, I need to ask this question here.
When I attempt to make a Oauth Call to Instagram by retrieved token it will return an error message below:
{"code": 400, "error_type": "OAuthException", "error_message": "Matching code was not found or was already used."}
I have included by code below for your observation:
private function getLoginURL($scopes = array("basic")) {
return self::API_OAUTH_URL."/?client_id=".self::CLIENT_ID."&redirect_uri=".self::REDIRECT_URI."&scope=".implode("+", $scopes)."&response_type=code";
}
private function auth() {
$api_data = array(
'client_id' => self::CLIENT_ID,
'client_secret' => self::CLIENT_SECRET,
'grant_type' => 'authorization_code',
'redirect_uri' => urlencode(self::TOKEN_URL),
'code' => self::TOKEN
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, self::TOKEN_URL);
curl_setopt($ch, CURLOPT_POST, count($api_data));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($api_data));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 90);
$json_data = curl_exec($ch);
curl_close($ch);
//return json_decode($json_data, true);
return $json_data;
}
Could someone help me out :(
Upvotes: 0
Views: 1337
Reputation: 456
Problem: Your response type is code
.
token
.This may require some reworking of your existing code.
While using token
, the scope specification comes afterwards.
private function getLoginURL($scopes = array("basic")) {
return self::API_OAUTH_URL."/?client_id=".self::CLIENT_ID."&redirect_uri=".self::REDIRECT_URI."&response_type=token&scope=".implode("+", $scopes);
}
Upvotes: 1