问题
I want to Use Paypal Connect API using Connect With PayPal Integrate https://developer.paypal.com/docs/connect-with-paypal/integrate/ Anyone who has done it before because I am having such errors.
I have integrate this Successfully till 5th step, but here in 6th step I cant hit API successfully
This is my request:
Method: POST, RequestUri: 'https://api.sandbox.paypal.com/v1/oauth2/token?grant_type=authorization_code&code={CodeProvided}', Version: 1.1, Content: , Headers: { Authorization: Basic {clientId}:{secret} }
and this is the error i got:
{"error":"invalid_client","error_description":"Client Authentication failed"}
This snippet of my code:
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", $"{clientId}:{clientSecret}");
HttpResponseMessage response = client.PostAsync($"https://api.sandbox.paypal.com/v1/oauth2/token?grant_type=authorization_code&code={code}",null).Result;
and this is the URL that i got:
https://www.example.com/Home/PaypalAuth?code=C21AAFXblx1g8x1ryZfCh6fIEesnuQ-47B3ObeF3toP50oYfUoqfCyZ8l6Yet9rRJ2E9RJfl-kDhzS9Xsw1LJVm8w5pblpqiw&scope=openid
However, I have also changed my secret and client id to base64 and checked but couldn't get desired response.
I have also added = at last to auhtentication for checking still it returns error.
I have also set body with json and put it as content in post content instead of null. like this:
ConnectPaypalBody body = new ConnectPaypalBody();
body.code = code;
body.grant_type = "authorization_code";
var json = JsonConvert.SerializeObject(body);
var data = new StringContent(json, Encoding.UTF8, "application/json");
HttpResponseMessage response = client.PostAsync($"https://api.sandbox.paypal.com/v1/oauth2/token?grant_type=authorization_code&code={code}",data).Result;
来源:https://stackoverflow.com/questions/61479783/anyone-who-have-used-paypal-connect-integration-paypal-connect-that-is-used-to