如何使用节点检索PayPal REST Api访问令牌
一旦你有一个PayPal客户端ID和客户端密钥,您可以使用以下方法:
var request = require('request');
request.post({
uri: "https://api.sandbox.paypal.com/v1/oauth2/token",
headers: {
"Accept": "application/json",
"Accept-Language": "en_US",
"content-type": "application/x-www-form-urlencoded"
},
auth: {
'user': '---your cliend ID---',
'pass': '---your client secret---',
// 'sendImmediately': false
},
form: {
"grant_type": "client_credentials"
}
}, function(error, response, body) {
console.log(body);
});
的响应,如果成功,将是东西,如下:
{
"scope":"https://api.paypal.com/v1/payments/.* ---and more URL callable with the access-token---",
"access_token":"---your access-token---",
"token_type":"Bearer",
"app_id":"APP-1234567890",
"expires_in":28800
}
你可以使用PayPal-Node-SDK拨打PayPal Rest API。它处理您的所有授权和身份验证。
您所说的大部分需求都是如此,但对于“支付体验/网络配置文件”而言并非如此。 – matteo 2015-02-09 17:14:14
同样,不是nodejs工程师,但是,我发现PayPal-Node-SDK也有样本用于https://github.com/paypal/PayPal-node-SDK/tree/master/samples/payment_experience/web_profile – 2015-02-09 17:19:53
让我知道您是否仍然使用node-sdk发现问题。我们很乐意帮助解决/更新问题,让您更快地整合paypal apis。 – 2015-02-21 06:57:33
这里是我将SuperAgent
superagent.post('https://api.sandbox.paypal.com/v1/oauth2/token')
.set("Accept","application/json")
.set("Accept-Language","en_US")
.set("content-type","application/x-www-form-urlencoded")
.auth("Your Client Id","Your Secret")
.send({"grant_type": "client_credentials"})
.then((res) => console.log("response",res.body))
非常感谢您的回复是如何得到的access_token!我如何获得“access_token”,我已经尝试过这样的“body.access_token”,但它返回undefined。 – Dimitri 2017-10-07 10:37:46