[英]Paypal Java script integration
Want to integrate Paypal with my mobile web application. 想要将Paypal与我的移动网络应用程序集成。 I tried to get the access token using client id and secret id but unable to get the access token. 我试图使用客户端ID和密码ID获取访问令牌,但无法获取访问令牌。
Below is the sample Ajax call with I am making to retrieve the access token. 下面是我正在进行的Ajax调用示例,用于检索访问令牌。
function getAccessToken(){
$.ajax({
url:"https://api.sandbox.paypal.com/v1/oauth2/token/",
type:"POST",
data : {"grant_type":"client_credentials"},
beforeSend: function (request)
{
request.setRequestHeader("Accept", "application/json");
request.setRequestHeader("Accept-Language", "en_US");
request.setRequestHeader("Authorization", "abc XXXXX:XXXXXXXXXXXXX");
},
success: function(data) {
alert(data);
},
error: function(e, messgae,type){
alert("Error" + e +" "+messgae+" type "+type);
}
});
I am unable to retrive the access token from the server. 我无法从服务器中检索访问令牌。 Can anyone please tell me how can I integrate Paypal with my mobile web application using java script? 任何人都可以告诉我如何使用Java脚本将Paypal与我的移动Web应用程序集成?
after a series of try and fail I found the correct AJAX call: 经过一系列尝试和失败后,我找到了正确的AJAX调用:
$.ajax({
headers: {
"Accept": "application/json",
"Accept-Language": "en_US",
"Authorization": "Basic "+btoa("**<Client ID>:<Secret>**")
},
url: "https://api.sandbox.paypal.com/v1/oauth2/token",
type: "POST",
data: "grant_type=client_credentials",
complete: function(result) {
alert(JSON.stringify(result));
},
});
You need to replace Client ID:Secret with the one that you find on your Developer Dashboard, for example AxxhGDh:hudh-X-h8qi 您需要将Client ID:Secret替换为您在Developer Dashboard上找到的那个,例如AxxhGDh:hudh-X-h8qi
Above example doesn't works, below works for me: 以上示例不起作用,下面适用于我:
var parameter = {
"grant_type": "client_credentials",
"username": "<username>",
"password": "<password>"
}
$.ajax({
headers: {
"Accept": "application/json",
"Accept-Language": "en_US",
"Authorization": "Basic <your auth key>"
},
url: "https://api.sandbox.paypal.com/v1/oauth2/token",
type: "POST",
data: parameter,
complete: function (result) {
alert(JSON.stringify(result));
},
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.