gpt4 book ai didi

angularjs - 带 Angular 的 Paypal API | 400(错误请求)

转载 作者:太空宇宙 更新时间:2023-11-03 16:17:46 25 4
gpt4 key购买 nike

我正在使用 paypal API 并使用此文档 make your firest call .

我收到状态代码 400(错误请求)和一条错误消息:

对象{error: "invalid_request", error_description: "grant_type is a required parameter"

'Authorization': "Basic RU9KMlMtWjZPb05fbGVfS1MxZDc1d3NaNnkwU0ZkVnNZOTE4M0l2eEZ5WnA6RUNsdXNNRVVrOGU5aWhJN1pkVkxGNWNaNnkwU0ZkVnNZOTE4M0l2eEZ5WnA=",

在本例中,我使用了示例提供的 Client-Id 和 Secret,并将它们编码为 base 64。

$http({
url: 'https://api.sandbox.paypal.com/v1/oauth2/token',
method: 'POST',
headers: {'Content-Type': 'application/x-www-form-urlencoded',
'Authorization': "Basic RU9KMlMtWjZPb05fbGVfS1MxZDc1d3NaNnkwU0ZkVnNZOTE4M0l2eEZ5WnA6RUNsdXNNRVVrOGU5aWhJN1pkVkxGNWNaNnkwU0ZkVnNZOTE4M0l2eEZ5WnA=",
'Accept-Language': 'en_US'
},
data: { grant_type: 'client_credentials' }
}).success(function (data, status, headers, config) {
console.log(data)
}).error(function (data, status, headers, config) {
console.log(data)
});

最佳答案

根本原因是您的数据被编码为 JSON 而不是 application/x-www-form-urlencoded,因此您需要做的是对数据进行 URL 编码,例如:

$http({
method: 'POST',
url: url,
data: $.param({grant_type: 'client_credentials'}),
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
})

关于angularjs - 带 Angular 的 Paypal API | 400(错误请求),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28384174/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com