地理位置与网络定位

旅行解析器API

Trip Parser API可从非结构化旅行文件中提取结构化数据,如航班、酒店和租车预订信息。它支持多种文件格式,帮助开发者快速集成旅行数据。该API需要先获取访问令牌才能使用。

查看官方文档 ↗

接入教程

1. 阅读Amadeus授权指南获取访问令牌
2. 准备您的旅行文件(如邮件、PDF)
3. 调用Trip Parser API上传文件
4. 解析返回的JSON格式结构化数据
5. 将数据集成到您的应用程序中
6. 根据需要处理错误和验证结果

使用Python解析旅行文件

python
import requests

# 设置API端点
url = "https://api.example.com/v3/trip-parser"
headers = {
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/pdf"
}

# 读取旅行文件
with open("travel_document.pdf", "rb") as file:
    file_data = file.read()

# 发送解析请求
response = requests.post(url, headers=headers, data=file_data)

if response.status_code == 200:
    parsed_data = response.json()
    print("解析成功:", parsed_data)
else:
    print(f"请求失败,状态码: {response.status_code}", response.text)

使用PHP提取旅行数据

php
<?php

$url = "https://api.example.com/v3/trip-parser";
$apiKey = "YOUR_API_KEY";
$filePath = "travel_document.pdf";

// 准备请求头
$headers = [
    "Authorization: Bearer " . $apiKey,
    "Content-Type: application/pdf"
];

// 读取文件内容
$fileContent = file_get_contents($filePath);

// 初始化cURL
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fileContent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

// 发送请求
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if ($httpCode == 200) {
    $parsedData = json_decode($response, true);
    echo "解析成功: " . print_r($parsedData, true);
} else {
    echo "请求失败,状态码: " . $httpCode . "\n";
    echo "响应: " . $response;
}
?>

使用JavaScript处理旅行文档

javascript
const fetch = require('node-fetch'); // 在Node.js环境中使用
const fs = require('fs');

async function parseTripDocument() {
    const url = "https://api.example.com/v3/trip-parser";
    const apiKey = "YOUR_API_KEY";
    const filePath = "travel_document.pdf";

    // 读取文件
    const fileData = fs.readFileSync(filePath);

    // 发送请求
    try {
        const response = await fetch(url, {
            method: 'POST',
            headers: {
                "Authorization": `Bearer ${apiKey}`,
                "Content-Type": "application/pdf"
            },
            body: fileData
        });

        if (response.ok) {
            const parsedData = await response.json();
            console.log("解析成功:", parsedData);
        } else {
            console.error(`请求失败,状态码: ${response.status}`);
            console.error(await response.text());
        }
    } catch (error) {
        console.error("请求出错:", error);
    }
}

parseTripDocument();

常见问题

Trip Parser API支持哪些文件格式?

Trip Parser API支持多种常见旅行文件格式,包括PDF、PNG、JPEG等图像格式,以及文本格式。建议使用清晰、高质量的文档以获得最佳解析效果。

如何获取API访问令牌?

使用Trip Parser API前,需先获取访问令牌。请参考官方授权指南生成令牌,并在请求头中使用Bearer令牌进行身份验证。

API请求失败常见原因有哪些?

常见失败原因包括:无效或过期的访问令牌、不支持的文件格式、文件大小超出限制、网络连接问题或服务器暂时不可用。请检查令牌有效性、文件格式及网络状态。

相似接口推荐

Amazon HealthLake

Amazon HealthLake 是一项符合 HIPAA 标准的服务,允许客户在云端以一致的方式存储、转换、查询和分析其符合 FHIR 格式的数据。

待确认
Amazon GameLift

Amazon GameLift提供基于会话的云端多人游戏服务器托管解决方案,包含部署、运营和扩展游戏服务器的工具。它基于亚马逊全球计算基础设施,帮助开发者实现高性能、高可靠性、低延迟的游戏体验,并支持灵活的服务器扩展和成

待确认
AWS Marketplace Entitlement Service

AWS Marketplace Entitlement Service用于确定客户对特定产品的使用权限。权限代表产品的容量授权,该API提供相关接口的描述和操作指南。

待确认
AWS Direct Connect

AWS Direct Connect 通过标准以太网光纤电缆将您的内部网络连接到 AWS Direct Connect 接入点。电缆一端连接您的路由器,另一端连接 AWS 路由器。建立此连接后,您可以直接创建虚拟接口访问

待确认