2015-02-06 148 views

回答

6

一旦你有一個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 
} 
+0

非常感謝您的回覆是如何得到的access_token!我如何獲得「access_token」,我已經嘗試過這樣的「body.access_token」,但它返回undefined。 – Dimitri 2017-10-07 10:37:46

0

你可以使用PayPal-Node-SDK撥打PayPal Rest API。它處理您的所有授權和身份驗證。

+0

您所說的大部分需求都是如此,但對於「支付體驗/網絡配置文件」而言並非如此。 – matteo 2015-02-09 17:14:14

+1

同樣,不是nodejs工程師,但是,我發現PayPal-Node-SDK也有樣本用於https://github.com/paypal/PayPal-node-SDK/tree/master/samples/payment_experience/web_profile – 2015-02-09 17:19:53

+0

讓我知道您是否仍然使用node-sdk發現問題。我們很樂意幫助解決/更新問題,讓您更快地整合paypal apis。 – 2015-02-21 06:57:33

0

這裏是我將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)) 
相關問題