接入教程
1. 访问Amadeus开发者网站注册账户。
2. 在控制台创建应用并获取API密钥。
3. 阅读授权指南生成访问令牌。
4. 使用机场或城市名称调用API端点。
5. 解析返回的JSON数据以获取详细信息。
6. 在测试环境中验证功能后部署到生产环境。
Python搜索机场示例
import requests
url = 'https://api.example.com/v1/reference-data/locations'
params = {
'subType': 'AIRPORT',
'keyword': 'LON',
'page[limit]': 10
}
headers = {
'Authorization': 'Bearer YOUR_API_KEY'
}
response = requests.get(url, headers=headers, params=params)
if response.status_code == 200:
data = response.json()
print(data)
else:
print(f'Error: {response.status_code}')
print(response.text)
PHP城市搜索示例
<?php
$url = 'https://api.example.com/v1/reference-data/locations';
$queryParams = [
'subType' => 'CITY',
'keyword' => 'Paris',
'page[limit]' => 5
];
$headers = [
'Authorization: Bearer YOUR_API_KEY'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url . '?' . http_build_query($queryParams));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode == 200) {
$data = json_decode($response, true);
print_r($data);
} else {
echo 'Error: ' . $httpCode . '\n';
echo $response;
}
?>
JavaScript获取位置详情
const url = 'https://api.example.com/v1/reference-data/locations/CITY';
const params = new URLSearchParams({
'keyword': 'Tokyo',
'page[limit]': 3
});
fetch(`${url}?${params}`, {
headers: {
'Authorization': 'Bearer YOUR_API_KEY'
}
})
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error: ${response.status}`);
}
return response.json();
})
.then(data => {
console.log(data);
})
.catch(error => {
console.error('Error:', error);
});
常见问题
如何获取API访问令牌?
请参考官方授权指南生成访问令牌。测试环境需要先在开发者门户注册并获取API密钥,然后通过OAuth 2.0客户端凭证流程获取令牌。
搜索API支持哪些查询参数?
主要参数包括subType(AIRPORT/CITY)、keyword(搜索关键词)、page[limit](返回结果数量)。具体参数请查阅API文档。
测试环境与生产环境有什么区别?
测试环境基于生产环境的子集,数据可能不完整或为模拟数据,主要用于集成测试和开发验证,不建议用于生产场景。
Aitishiku.com