Reputation: 453
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,
Upvotes: 25
Views: 23713
Reputation: 1293
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.
Upvotes: 0
Reputation: 3038
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.
Upvotes: 57
Reputation: 453
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);
Upvotes: 3
Reputation: 17545
If you are using Postman, do remember it's a POST request. Use form data
Upvotes: 10
Reputation: 9646
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
Upvotes: 4