Ajai
Ajai

Reputation: 11

LinkedIn access token api returns bad request error in c#

I am using linked oauth 2 api to fetch the access token.But I am getting a 400 (BadRequest) response from that api.I am sharing the code below

NameValueCollection parameters = new NameValueCollection();
parameters.Add("grant_type", "authorization_code");
parameters.Add("code", Code);
parameters.Add("redirect_uri", RedirectURL);
parameters.Add("client_id", ClientId);
parameters.Add("client_secret", ClientSecret);


WebClient client = new WebClient();
client.Headers[HttpRequestHeader.ContentType]="application/x-www-form-urlencoded";
var result = client.UploadValues("https://www.linkedin.com/oauth/v2/accessToken", parameters);

Could anyone help me to find what went wrong here. I am passing the correct values for all parameters, got client_id, client_secret from my application and the code I am getting from my initial authorization request.

I am not able to test this scenario in postman since the auth-token request depends on the code generated from the authorization step.

Upvotes: 0

Views: 2342

Answers (1)

Related Questions