下面是请求的post body
作为响应,我得到一个包含空数组的data
对象和一个具有length: 0
属性的meta
对象。
但是那天有航班:https://www.google.com/travel/flights/search?tfs=CBwQAhojagwIAhIIL20vMDRqcGwSCjIwMjMtMDUtMTRyBwgBEgNNQU4aI2oHCAESA01BThIKMjAyMy0wNS0xOXIMCAISCC9tLzA0anBscAGCAQsI____________AUABSAGYAQE
我以前有工作岗位请求,但是我已经删除了originRadius和destinationRadius选项来限制机场。
在这种情况下,我将从所有伦敦机场(LON)到曼彻斯特机场(MAN)。
我期待任何+/- 3天(I3D)的航班和这些天的任何时间。
{
"currencyCode": "USD",
"originDestinations": [
{
"id": "1",
"originLocationCode": "LON",
"destinationLocationCode": "MAN",
"departureDateTimeRange": {
"date": "2023-05-14",
"dateWindow": "I3D",
"time": "12:00:00",
"timeWindow": "12H"
}
},
{
"id": "2",
"originLocationCode": "MAN",
"destinationLocationCode": "LON",
"departureDateTimeRange": {
"date": "2023-05-19",
"dateWindow": "I3D",
"time": "12:00:00",
"timeWindow": "12H"
}
}
],
"travelers": [
{
"id": "1",
"travelerType": "ADULT"
}
],
"sources": [
"GDS"
],
"searchCriteria": {
"maxFlightOffers": 7,
"oneFlightOfferPerDay": true,
"flightFilters": {
"cabinRestrictions": [
{
"cabin": "ECONOMY",
"coverage": "ALL_SEGMENTS",
"originDestinationIds": [
"1",
"2"
]
}
],
"connectionRestrictions": {
"maxNumberOfConnections": 1
}
}
}
}
编辑:这就是我请求flightoffer的方式:
private async searchFlightOffers(flightSearchBody: FlightSearchBody): Promise<FlightOffersResponse> {
const accessToken = await this.getAccessToken();
const apiUrl = 'https://test.api.amadeus.com/v2/shopping/flight-offers';
console.log(`Searching for flight offers between ${flightSearchBody.originDestinations[0].originLocationCode} to ${flightSearchBody.originDestinations[0].destinationLocationCode}...`, flightSearchBody)
console.log('Using access token: ' + accessToken)
try {
const response = await fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${accessToken}`,
},
body: JSON.stringify(flightSearchBody),
});
const data = await response.json();
if (data.warnings) {
console.warn('Warnings returned from flight search: ', data.warnings);
}
console.log(data)
return data;
} catch (error: any) {
console.error(`Failed to search for flight offers: ${error.message}`);
throw error;
}
}
我的getAccessToken()
方法是可靠的,如果访问令牌不好,我将得到一个错误消息。
根据您的代码片段,您正在使用Amadeus API的测试环境。此环境不提供实时数据,相反,它是"有限的"。和";cached"。这可能是Amadeus API响应与你在谷歌上搜索不匹配的原因。
您可以在这里找到更多信息:
- https://developers.amadeus.com/blog/test-and-production-environments-for-amadeus-self-service-apis-
- https://amadeus4dev.github.io/developer-guides/test-data/