接入教程
1. 阅读Amadeus授权指南生成访问令牌
2. 调用API端点提交航班查询请求
3. 处理返回的JSON数据获取价格信息
4. 集成到您的应用中进行测试
5. 根据需要调整参数优化查询
Python 查询航班报价价格
python
import requests
url = "https://api.example.com/v1/shopping/flight-offers/price"
headers = {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
}
payload = {
"data": {
"type": "flight-offers-pricing",
"flightOffers": [
{
"type": "flight-offer",
"id": "1"
}
]
}
}
response = requests.post(url, headers=headers, json=payload)
print(response.status_code)
print(response.json())
PHP 获取航班报价价格
php
<?php
$url = "https://api.example.com/v1/shopping/flight-offers/price";
$headers = [
"Authorization: Bearer YOUR_API_KEY",
"Content-Type: application/json"
];
$data = [
"data" => [
"type" => "flight-offers-pricing",
"flightOffers" => [
[
"type" => "flight-offer",
"id" => "1"
]
]
]
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
$response = curl_exec($ch);
curl_close($ch);
echo $response;
?>
JavaScript 请求航班报价价格
javascript
fetch("https://api.example.com/v1/shopping/flight-offers/price", {
method: "POST",
headers: {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
},
body: JSON.stringify({
data: {
type: "flight-offers-pricing",
flightOffers: [
{
type: "flight-offer",
id: "1"
}
]
}
})
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error("Error:", error));
常见问题
如何获取API访问令牌?
请参考Amadeus官方授权指南生成访问令牌,在请求头中使用Bearer令牌进行身份验证。
测试环境和生产环境有什么区别?
测试环境基于生产环境的子集,主要用于开发和集成测试,可能不包含完整的航班数据。
请求频率是否有限制?
是的,API通常有请求频率限制,具体限制请查阅相关文档或联系API提供商。
Aitishiku.com