如何获得带有相应代码的城市和机场的完整列表?
How to get full list of cities and airports with their corresponding codes?
我正在使用 Amadeus 自助服务构建一个旅游预订网站 web-service。我已经到了这样的地步,我希望用户能够使用实际名称而不是 IATA 代码来搜索对城市或机场执行相对搜索。问题是 Amadeus API 并没有真正为我解决这个问题。之所以这样,是因为请求过程要求我在请求参数中包含国家代码。无论如何我可以在没有 countryCode 字段的情况下实现这一点吗?
在 header 中包含访问令牌之后。我明白了。 https://i.stack.imgur.com/9OqZn.png
```async function airportAndCitySearch(keyword) {
console.log("Searching " + keyword);
var form = new FormData();
var settings = {
"url": "https://test.api.amadeus.com/v1/reference-data/locations?subType=CITY,AIRPORT&keyword=" + keyword + "&countryCode=DE",
"method": "GET",
"timeout": 0,
"processData": false,
"mimeType": "multipart/form-data",
"contentType": false,
"data": form
};```
我通过这个请求成功获得了访问令牌。
console.log("Requesting Token...");
var settings = {
"url": "https://test.api.amadeus.com/v1/security/oauth2/token",
"method": "POST",
"timeout": 0,
"data": {
"client_id": CLIENT_ID,
"client_secret": CLIENT_SECRET,
"grant_type": "client_credentials"
}
};
$.ajax(settings).done(function (response) {
console.log("Assigning Token variables...");
ACCESS_TOKEN = response.access_token;
console.log("Access Token : " + ACCESS_TOKEN);
});
}
Amadeus 有一个不需要国家代码的端点。
端点:
GET https://test.api.amadeus.com/v1/reference-data/locations?subType=AIRPORT,CITY&keyword=r&page[limit]=5
示例:
我正在使用 Amadeus 自助服务构建一个旅游预订网站 web-service。我已经到了这样的地步,我希望用户能够使用实际名称而不是 IATA 代码来搜索对城市或机场执行相对搜索。问题是 Amadeus API 并没有真正为我解决这个问题。之所以这样,是因为请求过程要求我在请求参数中包含国家代码。无论如何我可以在没有 countryCode 字段的情况下实现这一点吗?
在 header 中包含访问令牌之后。我明白了。 https://i.stack.imgur.com/9OqZn.png
```async function airportAndCitySearch(keyword) {
console.log("Searching " + keyword);
var form = new FormData();
var settings = {
"url": "https://test.api.amadeus.com/v1/reference-data/locations?subType=CITY,AIRPORT&keyword=" + keyword + "&countryCode=DE",
"method": "GET",
"timeout": 0,
"processData": false,
"mimeType": "multipart/form-data",
"contentType": false,
"data": form
};```
我通过这个请求成功获得了访问令牌。
console.log("Requesting Token...");
var settings = {
"url": "https://test.api.amadeus.com/v1/security/oauth2/token",
"method": "POST",
"timeout": 0,
"data": {
"client_id": CLIENT_ID,
"client_secret": CLIENT_SECRET,
"grant_type": "client_credentials"
}
};
$.ajax(settings).done(function (response) {
console.log("Assigning Token variables...");
ACCESS_TOKEN = response.access_token;
console.log("Access Token : " + ACCESS_TOKEN);
});
}
Amadeus 有一个不需要国家代码的端点。
端点:
GET https://test.api.amadeus.com/v1/reference-data/locations?subType=AIRPORT,CITY&keyword=r&page[limit]=5
示例: