【问题标题】:How to curl to paypal in nodejs?如何在nodejs中卷曲到贝宝?
【发布时间】:2015-03-28 10:23:53
【问题描述】:

我正在尝试使用请求在 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 的文档:Request

console.log(error): null


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

【问题讨论】:

  • 响应状态码是什么?
  • 请在回调中加入一个 console.log(error) 并告诉我们你看到了什么。

标签: node.js curl paypal


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2015-04-18
    • 2016-05-01
    • 2018-12-02
    • 2011-08-07
    • 2011-07-25
    • 1970-01-01
    • 2017-03-05
    • 2016-04-12
    • 2021-08-18
    相关资源
    最近更新 更多