【发布时间】:2019-08-04 12:22:40
【问题描述】:
我正在尝试使用以下 URL 中的说明获取 PayPal 访问令牌:https://developer.paypal.com/docs/api/overview/#get-an-access-token
我已按照信件 URL 中的说明进行操作,并在 JavaScript 中构建了以下示例代码。当我运行它时,我收到 401 错误 - 用户未授权。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<h1>Get Access Token</h1>
<script>
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
console.log(xhttp.responseText);
}
else {
console.log("Status: " + xhttp.status)
}
};
url = "https://api.sandbox.paypal.com/v1/oauth2/token"
clientID = "AY_6HpYodeIdCyCSWmIuTTX6P4PfcO1tcehekaSk9uwSBhav1SILCD0MZ_E3dRMVXiPdmE-YimahYtQy"
secret = "EHLlKnunCQtuTdqjnl6QX9ZnuQgMllZKozf-VNHeys9tDssQc0xlXi4_0se1M-VxT8gOHGaSVS3M-2an"
xhttp.open("post", url, false, clientID, secret);
xhttp.setRequestHeader("Accept", "application/json");
xhttp.setRequestHeader("Accept-Language", "en_US");
xhttp.setRequestHeader("content-type", "application/x-www-form-urlencoded");
xhttp.send("grant_type=client_credentials");
console.log(xhttp.status);
</script>
</body>
</html>
clientID 和 secret 来自 PayPal My Apps and Credentials 链接:
PayPal My Apps and Credentials Page
有人可以帮忙吗?谢谢
【问题讨论】:
标签: paypal