如何使用节点检索 PayPal REST Api 访问令牌 [英] How to retrieve PayPal REST Api access-token using node
本文介绍了如何使用节点检索 PayPal REST Api 访问令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用节点获取利用 REST Api 所需的 PayPal 访问令牌?
How to get the PayPal access-token needed to leverage the REST Api by using node?
推荐答案
一旦您拥有 PayPal 客户 ID 和客户机密,您就可以使用以下内容:
Once you have a PayPal client Id and a Client Secret you can use the following:
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);
});
如果成功,响应将如下所示:
The response, if successful, will be something as the following:
{
"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 REST Api 访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文