Mao*_*hen 5 c# asp.net-mvc paypal
我正在尝试获取我的贝宝访问令牌。
我有下一个参数:EndPoint
, Client Id
, secret
, api username
, api signature
, api password
, application Id
。
我应该需要一个贝宝客户才能做到这一点吗?
我点击了这个链接:https : //developer.paypal.com/docs/integration/direct/make-your-first-call/
并尝试:
private string getAccessToken() {
var ppClient; // = new paypalClient(); // create a paypal client
Dictionary<string, object> parameters = new Dictionary<string, object>();
parameters.Add("Accept", "application/json");
parameters.Add("Accept-Language", "en_US");
parameters.Add("grant_type", "client_credentials");
var result = ppClient.Get("https://api.sandbox.paypal.com/v1/oauth2/token", parameters);
string accessToken = result["access_token"];
return accessToken;
}
Run Code Online (Sandbox Code Playgroud)
谢谢你们!
我建议使用 RestSharp(只需获取 NuGet 包):-
if (ServicePointManager.SecurityProtocol != SecurityProtocolType.Tls12) ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; // forced to modern day SSL protocols
var client = new RestClient(payPalUrl) { Encoding = Encoding.UTF8 };
var authRequest = new RestRequest("oauth2/token", Method.POST) {RequestFormat = DataFormat.Json};
client.Authenticator = new HttpBasicAuthenticator(clientId, secret);
authRequest.AddParameter("grant_type","client_credentials");
var authResponse = client.Execute(authRequest);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3171 次 |
最近记录: |