9
votes

I am trying to use Instagram Basic display API but when I post the authorization code to get the access token I keep getting the following error

{"error_type": "OAuthException", "code": 400, "error_message": "Invalid platform app"}

I am following all the steps mentioned here -> https://developers.facebook.com/docs/instagram-basic-display-api/getting-started and Yes I am using the Instagram app ID and It's client secret which is in Products -> Instagram -> Display and following is the URL I am sending the request

"https://api.instagram.com/oauth/access_token?client_id=".$app_id."&client_secret=".$app_secret."&grant_type=authorization_code&redirect_uri=".$redirecturi."&code=".$code,

5
Have you added your Instagram account to the tester section in the dashboard? And if you visit Instagram on the web are you definitely logged into that account and not another one? - TommyBs
Yes, I have added the tester account and when I click the login button it takes me to this screen. Yes, I am logged in with the same account on Instagram.com which I added as a test account check screenshot - Danish Ali Malik
Even if I remove all the parameters from the request It sends the same error nothing like "Client ID is missing etc." - Danish Ali Malik
How did you get the code? - SpaceDogCS

5 Answers

4
votes

When you exchange the code you need to use a POST request.

From the looks of your url, you've formed it as a GET request with all the parameters as part of the url rather than as form data. Try sending the parameters as part of the post body instead

15
votes

I ran into this same issue. Problem was I was using the Facebook App ID and App Secret instead of the Instagram App ID & App Secret. You must go to the "Instagram Basic Display" section on the Facebook developers site then scroll down until you find the Instagram App ID & Secret.

9
votes

If you are using Postman, do remember it's a POST request. Use form data

enter image description here

3
votes

Working example code:

$curl = curl_init();
curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.instagram.com/oauth/access_token",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 0,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => array('client_id' => '{client_id}','client_secret' => '{client_secret}','grant_type' => 'authorization_code','redirect_uri' => '{redirect_uri}','code' => '{code}'),
  CURLOPT_HTTPHEADER => array(
    "Content-Type: multipart/form-data; boundary=--------------------------780367731654051340650991"
  ),
));
$response = curl_exec($curl);
curl_close($curl);
print_r($response);
0
votes

I have got this error for the below reason.

If any case, App Id and Secret Key are blank then this type of error is generated. so we can first test first that that app id and secret key must be the correct one. I know that this is a very normal thing that we can notice easily. But sometimes, we can not notice some simple things.