我只是试着向amadeus API发出一个请求。
我已经有了API密钥和API密钥,我传入了XHR header Authorization和我的API密钥的值
这是我的JQuery:
$.ajax({
type: "get",
url: "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MIA&destination=SFOˆduration=15&nonStop=true",
dataType: 'json',
async: true,
beforeSend: function(xhr) {
xhr.setRequestHeader('Authorization',
'Basic ' + amadeusApiKey);
},
success: function(json) {
console.log(json);
}
});但是响应是HTTP代码401和主体
{
"errors": [
{
"code": 38190,
"title": "Invalid access token",
"detail": "The access token provided in the Authorization header is invalid",
"status": 401
}
],
}我是否应该使用API密钥和密钥进行一些编码,但在文档中找不到任何内容
发布于 2018-04-29 20:35:42
您尝试针对的API是使用Client credentials grant类型进行保护的。
在调用之前,您应该使用您的接口密钥/密钥生成访问令牌,请参考此guide。生成访问令牌后,您的请求应如下所示:
$.ajax({
type: "get",
url: "https://test.api.amadeus.com/v1/shopping/flight-dates?origin=MIA&destination=SFOˆduration=15&nonStop=true",
dataType: 'json',
async: true,
beforeSend: function(xhr) {
xhr.setRequestHeader('Authorization',
'Bearer ' + amadeusAccessToken);
},
success: function(json) {
console.log(json);
}
});或者,Amadeus提供了一些SDKs来抽象这种复杂性。
https://stackoverflow.com/questions/50080663
复制相似问题