如何通过Amadeus Python API获取旅游活动价格及相关信息?
Amadeus Python API 获取旅游活动价格、日期及机票捆绑信息方案
一、获取旅游活动的价格与可预订日期
你之前调用的amadeus.shopping.activity('ID').get()仅返回基础信息,要获取价格和日期选项,可使用以下两种方式:
1. 批量搜索目的地的活动(含价格)
通过shopping.activities接口搜索指定区域的活动,直接返回带价格、日期范围的结果:
# 搜索柏林2024年7月的旅游活动 activities = amadeus.shopping.activities.get( destination='BER', startDate='2024-07-01', endDate='2024-07-31', adults=1 ).data # 提取关键信息 for act in activities: print(f"活动名称:{act['name']}") print(f"价格:{act['price']['amount']} {act['price']['currency']}") print(f"可预订日期:{act['availability']['startDate']} ~ {act['availability']['endDate']}\n")
2. 获取单个活动的详细报价(含具体日期)
如果已有活动ID,调用activity(activity_id).offers接口获取该活动的具体报价(含实时价格、可预订日期、库存):
# 获取活动ID为56777的报价详情 activity_offers = amadeus.shopping.activity('56777').offers.get( adults=1, startDate='2024-07-05' ).data for offer in activity_offers: print(f"报价ID:{offer['id']}") print(f"总价:{offer['price']['total']} {offer['price']['currency']}") print(f"预订截止日期:{offer['bookingDates']['latestDateToBook']}\n")
二、判断旅游活动是否捆绑机票
活动详情的includedItems字段会列出所有包含的服务类型,通过此字段可判断是否有机票捆绑:
# 获取活动详情并检查是否含机票 activity_detail = amadeus.shopping.activity('56777').get().data included_services = activity_detail.get('includedItems', []) # 遍历服务类型,判断是否包含机票 has_flight = any(item['type'] == 'FLIGHT' for item in included_services) print("该活动捆绑有机票" if has_flight else "该活动未捆绑机票")
注意事项
- 确认你的API密钥已开通Shopping Activities和Activity Offers接口的访问权限,部分权限需额外申请
- 价格、库存可能随日期、人数变化,请求时需明确指定
adults、startDate等参数以获取准确结果 - 德国区域的套餐产品,可指定德国城市代码(如
MUC慕尼黑、HAM汉堡)作为destination筛选
内容的提问来源于stack exchange,提问作者Rollo99
相关产品推荐
相关产品推荐

