从刷新令牌获取Paypal访问令牌

时间:2016-11-09 08:09:41

标签: paypal-sandbox paypal

当我尝试通过cURL从刷新令牌获取access_token或邮递员成功获得响应时,

请求

POST /v1/oauth2/token HTTP/1.1
Host: api.sandbox.paypal.com
Content-Type: application/x-www-form-urlencoded
Authorization: Basic QVZZeWdRa2dSX3pScmtJT25PZXVz.....
Cache-Control: no-cache

grant_type=refresh_token&refresh_token=-Q1_6fEwUDQ0ci0CJIA......

RESULT

{
"scope":"phone https://uri.paypal.com/services/subscriptions https://api.paypal.com/v1/payments/.* address email https://api.paypal.com/v1/vault/credit-card https://uri.paypal.com/services/applications/webhooks https://uri.paypal.com/services/payments/futurepayments openid https://api.paypal.com/v1/vault/credit-card/.*","nonce":"2016-11-08T13:58:45Zm5eDiRGyJIDC9EwX7DRl6aB7IPlRl-cjoS_E3Ro8sCo",
"access_token":"A103.CfI6WQaDmEqrQ.....",
"token_type":"Bearer",
"app_id":"APP-80W28448....",
"expires_in":28796
}

但是当我像这样用paypal-net sdk做同样的事情时,

var apiContext = PaypalConfiguration.GetAPIContext();
var tokenInfo = new Tokeninfo();
tokenInfo.refresh_token = "-Q1_6fEwUDQ0ci0CJIA7BtG_Ey4i....";
var refreshTokenParams = new CreateFromRefreshTokenParameters();
var token = tokenInfo.CreateFromRefreshToken(apiContext, refreshTokenParams);

我一直得到这个回复,

{
"error_description":"POST /v1/oauth2/token returned a response status of 400 Bad Request",
"error":"400",
"correlation_id":"46ecefc761f3f",
"information_link":"https://developer.paypal.com/docs/api/#errors"
}

我的模式设置为沙箱,客户端ID和客户端密码适用于沙箱。

你能告诉我我错在哪里或Paypal-NET-SDK出了什么问题吗?

2 个答案:

答案 0 :(得分:0)

有一个错误fixed

答案 1 :(得分:0)

试试.Net SDK

 byte[] bytes = Encoding.UTF8.GetBytes("ClientId:ClientSecret");
            string base64 = Convert.ToBase64String(bytes);
            var client = new RestClient("https://api.sandbox.paypal.com/v1/identity/openidconnect/tokenservice");
            var request = new RestRequest(Method.POST);
            request.AddHeader("postman-token", "3c08eb6d-d6fb-a622-5d21-e9f1a6daa3ce");
            request.AddHeader("cache-control", "no-cache");
            request.AddHeader("content-type", "application/x-www-form-urlencoded");
            request.AddHeader("authorization", "Basic " + base64);
            request.AddParameter("application/x-www-form-urlencoded", "grant_type=refresh_token&refresh_token=" + dataFilter.RefreshToken, ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);