提问者:小点点

获取PayPal访问令牌,RestSharp返回状态代码:NOTFUND


获取PayPal访问令牌无效

我得到的回应是:

“statuscode:NotFound,content-type:application/json,content-length:131)”

我的代码,使用RestSharp

public void getToken()
{
    var clientId = "{client-ID}";
    var secret = "{client-secret}";

    if (ServicePointManager.SecurityProtocol != SecurityProtocolType.Tls12) ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; // forced to modern day SSL protocols
    var client = new RestClient("https://api.paypal.com/v1/oauth2/token") { Encoding = Encoding.UTF8 };
    var authRequest = new RestRequest("oauth2/token", Method.POST) { RequestFormat = DataFormat.Json };
    client.Authenticator = new HttpBasicAuthenticator(clientId, secret);
    authRequest.AddParameter("grant_type", "refresh_token&refresh_token={refresh_token}");
    var authResponse = client.Execute(authRequest);
}

我确实有一点感觉,我的可能是不正确的,因为我不是100%确定这里到底是什么,经过一些研究,我还是不清楚--但我使用了。虽然是静态的,但我不确定是否应该用一个值填充它,或者如何这样做。

有人知道我做错了什么吗?我对的怀疑是否正确?


共1个答案

匿名用户

你把小路折弯了。

new RestClient("https://api.paypal.com/v1/oauth2/token") 

这一行将该URL设置为基址,并将其前置到其他路径字符串中。因此,当您使用时,您最终获取的URL为

https://api.paypal.com/v1/oauth2/token/oauth2/token

只需从基址中删除路径字符串,就可以:

 new RestClient("https://api.paypal.com/v1")