金融与汇率

酒店搜索API

该API提供酒店搜索功能,支持查询全球酒店信息。使用前需获取访问令牌,测试环境基于生产环境的子集。

查看官方文档 ↗

接入教程

1. 阅读Amadeus授权指南获取访问令牌
2. 使用令牌调用酒店搜索API端点
3. 解析返回的JSON数据获取酒店列表
4. 根据需要筛选和展示酒店信息
5. 在生产环境部署前进行充分测试

Python示例:搜索酒店

python
import requests

url = "https://api.example.com/v1/hotels/search"
headers = {
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/json"
}
payload = {
    "cityCode": "NYC",
    "checkInDate": "2023-12-01",
    "checkOutDate": "2023-12-05",
    "roomQuantity": 1
}

response = requests.post(url, json=payload, headers=headers)
if response.status_code == 200:
    hotels = response.json()
    print(f"Found {len(hotels.get('data', []))} hotels")
else:
    print(f"Error: {response.status_code}", response.text)

PHP示例:获取酒店详情

php
<?php
$url = 'https://api.example.com/v1/hotels/details';
$apiKey = 'YOUR_API_KEY';
$data = [
    'hotelId' => '12345',
    'adults' => 2
];

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Authorization: Bearer ' . $apiKey,
    'Content-Type: application/json'
]);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));

$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if ($httpCode == 200) {
    $result = json_decode($response, true);
    echo "Hotel: " . $result['name'] . "\n";
} else {
    echo "Error: " . $httpCode . "\n";
    echo $response;
}
?>

JavaScript示例:按城市查询酒店

javascript
const fetch = require('node-fetch');

async function searchHotels() {
    const url = 'https://api.example.com/v1/hotels/by-city';
    const options = {
        method: 'POST',
        headers: {
            'Authorization': 'Bearer YOUR_API_KEY',
            'Content-Type': 'application/json'
        },
        body: JSON.stringify({
            cityCode: 'LON',
            radius: 5,
            radiusUnit: 'KM'
        })
    };

    try {
        const response = await fetch(url, options);
        if (response.ok) {
            const data = await response.json();
            console.log(`Found ${data.hotels.length} hotels in London`);
        } else {
            console.error(`HTTP Error: ${response.status}`);
        }
    } catch (error) {
        console.error('Request failed:', error);
    }
}

searchHotels();

常见问题

如何获取API访问令牌?

请参考官方授权指南生成访问令牌,测试环境需使用测试密钥,生产环境需申请正式密钥。

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

测试环境基于生产环境的子集,数据可能不完整或延迟更新,主要用于功能验证。

API支持哪些搜索参数?

支持城市代码、入住日期、离店日期、房间数量等基本参数,具体请查阅API文档。

相似接口推荐

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推理的加速计算资源。

待确认