Rah*_*hul 3 curl paypal oauth angularjs
The documentation says to obtain oauth token use the following :
curl -v https://api.sandbox.paypal.com/v1/oauth2/token \ -H "Accept: application/json" \ -H "Accept-Language: en_US" \ -u "EOJ2S-Z6OoN_le_KS1d75wsZ6y0SFdVsY9183IvxFyZp:EClusMEUk8e9ihI7ZdVLF5cZ6y0SFdVsY9183IvxFyZp" \ -d "grant_type=client_credentials"
How to send -u and -d parameters using angular js
var senddata = {
clientId:"Ac8T1BCmIxgxbS5O_ztwejxvNW8Cbr0y1724_2cd8bGl68axHyw_nEdcOBli",
secret:"EAwgXhALV78LnphCPf-R3zs1Dx3nkcIOMc4TftSLh9q5EpgyqdeE19El9Oh0",
grant_type:"client_credentials"
};
Run Code Online (Sandbox Code Playgroud)
Tried passing senddata in http.post(url,senddata)
But I am getting
{"error":"invalid_client","error_description":"Invalid client credentials"}
Run Code Online (Sandbox Code Playgroud)
我正在使用 Angular-JS 开发的电子商务解决方案的上下文中进行 PayPal API 调用。我能够使用以下代码从 PayPal 取回 auth_token。困扰我一段时间的两个问题是:
将数据作为对象发送时,data: {'grant_type': 'client_credentials'}我收到一个错误,指出“grant_type”是必需参数。将其更改为用等号连接的字符串后,我不再收到此错误。
var basicAuthString = btoa('CLIENTID:SECRET');
$http({
method: 'POST',
url: 'https://api.sandbox.paypal.com/v1/oauth2/token',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': 'Basic ' + basicAuthString,
},
data: 'grant_type=client_credentials'
})
.success(function(data){
console.log(data.access_token);
})
.error(function(error){
console.error(error);
});
Run Code Online (Sandbox Code Playgroud)我希望这对试图实现这一点的人有所帮助。
| 归档时间: |
|
| 查看次数: |
1760 次 |
| 最近记录: |