我想使用贝宝连接使用 Connect 与 PayPal 集成的 APIhttps://developer.paypal.com/docs/connect-with-paypal/integrate/ https://developer.paypal.com/docs/connect-with-paypal/integrate/以前做过的人,因为我犯了这样的错误。
我已经成功集成到第 5 步,但在第 6 步中我无法成功命中 API
这是我的要求:
方法:POST,RequestUri:'{CodeProvided}',版本:1.1,内容:,标题:{ 授权:基本 {clientId}:{secret} }
这是我得到的错误:
{“error”:“invalid_client”,“error_description”:“客户端身份验证失败”}
我的代码片段:
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;
这是我得到的网址:
但是,我也将我的秘密和客户端 ID 更改为 Base64 并进行了检查,但无法获得所需的响应。
我还添加了=最后进行身份验证检查仍然返回错误。
我还用 json 设置了 body 并将其作为帖子内容中的内容而不是 null 。像这样:
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;