0
我试图将PayPal付款合并到我们的项目中,但目前我失败了。PayPal API - (401)未经授权请求访问令牌
基本上,第一步是获取访问令牌请求和响应,我试图用WebRequest来做,但它在我身上吐出401。
从以下说明:https://developer.paypal.com/docs/integration/direct/make-your-first-call/
下面的代码:
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
WebRequest request = WebRequest.Create("https://api.sandbox.paypal.com/v1/oauth2/token");
request.ContentType = "application/x-www-form-urlencoded";
request.Method = "POST";
request.Credentials = new NetworkCredential("client_id", "secret");
request.PreAuthenticate = true;
string body = "grant_type=client_credentials";
byte[] buffer = Encoding.UTF8.GetBytes(body);
request.ContentLength = buffer.LongLength;
var reqStr = request.GetRequestStream();
reqStr.Write(buffer, 0, buffer.Length);
reqStr.Close();
WebResponse response = request.GetResponse();
Ofcourse,CLIENT_ID和秘密与代码:)
感谢您对实际值替换你的帮助!