Instagram Basic Display API: RestSharp Invalid authorization code response

Viewed 1566
  • Trying to to add an Instagram feed to my ASP.NET C# web app using this and this documentation
  • The issue is that I always get the Invalid authorization code error message when trying to get the short lived token via RestSharp call to https://api.instagram.com/oauth/access_token
  • In Postman the response is successful, is there something wrong with the RestSharp API call?

RestSharp API call

var client = new RestClient(_shortLivedTokenRequestString);
var request = new RestRequest(Method.POST);

request.AlwaysMultipartFormData = true;
request.AddParameter("client_id", _Instagram_App_Id, ParameterType.RequestBody);
request.AddParameter("client_secret", _Instagram_App_Secret, ParameterType.RequestBody);
request.AddParameter("grant_type", "authorization_code", ParameterType.RequestBody);
request.AddParameter("redirect_uri", _Instagram_App_Redirect_Uri, ParameterType.RequestBody);
request.AddParameter("code", authorizationCode, ParameterType.RequestBody);

IRestResponse<GetShortLivedTokenResponse> response = client.Execute<GetShortLivedTokenResponse>(request); 

response: {"error_type": "OAuthException", "code": 400, "error_message": "Invalid authorization code"}

response object

enter image description here

Postman request/response

enter image description here

Postman response headers

enter image description here

2 Answers

I recently had a similar problem that involved not removing the #_ added at the end of the code parameter like described here.

I don't know if thats your case but maybe it helps

My problem was that I did not remove the #_ as described in the instructions:

enter image description here

Related