金融与汇率

航班报价搜索API

此API用于搜索航班报价信息,提供实时航班数据查询功能。在使用前需参考授权指南获取访问令牌,测试环境基于生产环境子集。

查看官方文档 ↗

接入教程

1. 阅读授权指南生成访问令牌
2. 调用API端点搜索航班报价
3. 解析返回的航班数据结果
4. 处理错误响应并优化查询

Python搜索航班报价示例

python
import requests

# 获取访问令牌(示例)
token_url = 'https://test.api.amadeus.com/v1/security/oauth2/token'
token_data = {
    'grant_type': 'client_credentials',
    'client_id': 'YOUR_API_KEY',
    'client_secret': 'YOUR_API_SECRET'
}
token_response = requests.post(token_url, data=token_data)
access_token = token_response.json().get('access_token')

# 搜索航班报价
search_url = 'https://test.api.amadeus.com/v2/shopping/flight-offers'
headers = {'Authorization': f'Bearer {access_token}'}
params = {
    'originLocationCode': 'SYD',
    'destinationLocationCode': 'BKK',
    'departureDate': '2024-12-01',
    'adults': 1
}
response = requests.get(search_url, headers=headers, params=params)
print(response.json())

PHP搜索航班报价示例

php
<?php

// 获取访问令牌(示例)
$tokenUrl = 'https://test.api.amadeus.com/v1/security/oauth2/token';
$tokenData = array(
    'grant_type' => 'client_credentials',
    'client_id' => 'YOUR_API_KEY',
    'client_secret' => 'YOUR_API_SECRET'
);
$ch = curl_init($tokenUrl);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($tokenData));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$tokenResponse = curl_exec($ch);
$accessToken = json_decode($tokenResponse, true)['access_token'];
curl_close($ch);

// 搜索航班报价
$searchUrl = 'https://test.api.amadeus.com/v2/shopping/flight-offers';
$headers = array('Authorization: Bearer ' . $accessToken);
$params = array(
    'originLocationCode' => 'SYD',
    'destinationLocationCode' => 'BKK',
    'departureDate' => '2024-12-01',
    'adults' => 1
);
$ch = curl_init($searchUrl . '?' . http_build_query($params));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo $response;

?>

JavaScript搜索航班报价示例

javascript
// 获取访问令牌(示例)
async function getAccessToken() {
    const tokenUrl = 'https://test.api.amadeus.com/v1/security/oauth2/token';
    const tokenData = new URLSearchParams({
        grant_type: 'client_credentials',
        client_id: 'YOUR_API_KEY',
        client_secret: 'YOUR_API_SECRET'
    });
    const tokenResponse = await fetch(tokenUrl, {
        method: 'POST',
        headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
        body: tokenData
    });
    const tokenJson = await tokenResponse.json();
    return tokenJson.access_token;
}

// 搜索航班报价
async function searchFlightOffers() {
    const accessToken = await getAccessToken();
    const searchUrl = 'https://test.api.amadeus.com/v2/shopping/flight-offers';
    const params = new URLSearchParams({
        originLocationCode: 'SYD',
        destinationLocationCode: 'BKK',
        departureDate: '2024-12-01',
        adults: 1
    });
    const response = await fetch(`${searchUrl}?${params}`, {
        headers: { 'Authorization': `Bearer ${accessToken}` }
    });
    const data = await response.json();
    console.log(data);
}

searchFlightOffers();

常见问题

如何获取API访问令牌?

请参考Amadeus官方授权指南,使用您的客户端ID和密钥通过OAuth 2.0客户端凭证流程获取访问令牌。测试环境使用test.api.amadeus.com域名。

测试环境和生产环境有什么区别?

测试环境基于生产环境的子集,数据可能有限或为模拟数据,主要用于开发和集成测试,不建议用于生产流量。

搜索航班报价时需要哪些必需参数?

必需参数包括:出发地机场代码(originLocationCode)、目的地机场代码(destinationLocationCode)、出发日期(departureDate)和成人乘客数量(adults)。

相似接口推荐

AWS Import/Export

AWS Import/Export服务通过邮寄物理存储设备的方式,在AWS云和用户本地环境间高效传输海量数据。该服务利用亚马逊高速内部网络直接读写存储设备,适用于大规模数据迁移场景。

待确认
AWS Greengrass

AWS IoT Greengrass可将AWS功能无缝扩展至物理设备,使设备能够本地处理生成的数据,同时仍利用云端进行管理、分析和持久存储。该服务确保设备能够快速响应本地事件,并在间歇性连接下稳定运行。

待确认
Amazon ElastiCache

Amazon ElastiCache是一项Web服务,可简化云端分布式缓存的设置、操作和扩展。它让客户能够获得高性能内存缓存的所有优势,同时减少管理负担。

待确认
Amazon Elastic Inference

Elastic Inference是AWS提供的弹性推理服务公共API。自2023年4月15日起,AWS不再接受新客户使用该服务,并协助现有客户迁移至性价比更优的替代方案。该API用于管理云端AI推理的加速计算资源。

待确认