如何在nodejs中卷曲到paypal?

时间:2015-01-29 08:58:37

标签: node.js curl paypal

我正在尝试使用Request在Nodejs中使用cURL发布到PayPal的API,但得不到任何回报:

var consentJSONData = 'AuthorizationCodeForNoNetworkEnvironment';

var options = {
    url: 'https://api.paypal.com/v1/oauth2/token',
    qs: 'grant_type=authorization_code&response_type=token&redirect_uri=urn:ietf:wg:oauth:2.0:oob&code=' + consentJSONData,
    headers: {
        'Content-Type:': 'application/x-www-form-urlencoded',
        'Authorization' : 'Basic Y2xpZW50X2lkOnNlY3JldA=='
    }
};

function callback(error, response, body) {
    console.log(error); <- null
    console.log(response); <- a whole bunch of stuff, but don't see the json that I'm looking for.
    console.log(body); <- emtpy
}

request(options, callback);

我做错了什么?我甚至关闭了吗?

我正在使用我的沙盒,当授权用户以后付款时,我会收到此凭据密钥:AuthorizationCodeForNoNetworkEnvironment

另外,PayPal说要发送'client_id:secret',但我用base64编码,因为我不知道如何发送参数。也许这与它有关。

以下是PayPal的文档:PayPal SDK

以下是请求的文档:Request

console.log(错误):null


原来我对OAuth2一无所知,实际上是Base64'ing'client_id:secret',而不是PayPal提供的client_id和秘密。

1 个答案:

答案 0 :(得分:0)

PayPal的Node.js SDK被证明是最佳解决方案:https://github.com/paypal/PayPal-node-SDK