调用 DefaultApi->flightInspirationSearch 时出现异常:[400] 连接到 API 时出错
Exception when calling DefaultApi->flightInspirationSearch: [400] Error connecting to the API
我正在尝试开始使用 amadeus sandbox travel api
,并且刚刚开始使用 api
docs
<?php
require_once(__DIR__ . '/vendor/autoload.php');
$api_instance = new Swagger\Client\Api\DefaultApi();
$apikey = "jJtGVQ********************RONJZq1"; // string | API Key provided for your account, to identify you for API access. Make sure to keep this API key secret.
$origin = "NYC"; // string | <a href=\"https://en.wikipedia.org/wiki/International_Air_Transport_Association_airport_code\">IATA code</a> of the city from which the traveler will depart. See the location and airport interfaces for more information.
$destination = "LAX"; // string | <a href=\"https://en.wikipedia.org/wiki/International_Air_Transport_Association_airport_code\">IATA code</a> of the city to which the traveler is going
$departure_date = "2017-12-16--2017-12-26"; // string | Range of dates between which the traveler could depart. Dates are specified in the <a href=\"https://en.wikipedia.org/wiki/ISO_8601\">ISO 8601</a> yyyy-MM-dd date format. Ranges are inclusive and ranges of months will apply from the start to the end of the month. If just a single date is specified, only that date will be searched. By default, the date range starts today and applies up to 361 in the future is applied. Past dates are generally not supported, future dates should be in the next 361 days, although results start to become sparse after about 6 months in the future, as airlines may still be defining their schedules. The default is to search all future dates available.
$one_way = false; // bool | When set to true, the query will be for a single trip from the origin to the destination. When this parameter is not provided, or is set to false, the query is for a round trip from the origin to the destination and back again.
$duration = "1--15"; // string | The allowed duration or range of durations of the trip, in days. This parameter must not be set if the one-way parameter is set to true.
$direct = false; // bool | Limit the search to results that do not require the passenger to change plane?
$max_price = "100000"; // string | Maximum price of trips to find in the result set, in the currency specified for this origin and destination pair in the cache contents spreadsheet. So, for example, if the origin is NYC, and the max price is 400, this means 400 USD. If the origin is PAR, and the max price is 400, this means 400 EUR. By default, no limit is applied
$aggregation_mode = ""; // string | Specifies the granularity of results to be found. DESTINATION is the default and finds one result per city. COUNTRY finds one result per country, DAY finds on result for every day in the date range, WEEK finds one result for every week in the date range. Note that specifying a small granularity but a large search scope may result in a huge output. For some very large outputs, the API may refuse to provide a result.
try {
$result = $api_instance->flightInspirationSearch($apikey, $origin, $destination, $departure_date, $one_way, $duration, $direct, $max_price, $aggregation_mode);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling DefaultApi->flightInspirationSearch: ', $e->getMessage(), PHP_EOL;
}
?>
这是我用来执行搜索的示例代码
但它给我一个错误
调用时出现异常DefaultApi
flightInspirationSearch: [400] Error connecting to the API (https://api.sandbox.amadeus.com/v1.2/flights/inspiration-search?apikey=jJt*************************JZq1&origin=NYC&destination=LAX&departure_date=2017-12-16--2017-12-26&one-way=0&duration=1--15&direct=0&max_price=100000&aggregation_mode=)
如果有人能告诉我为什么会出现此错误,我将不胜感激,我实际上正在使用 xampp
在 windows 机器上进行本地测试 php > 7.0
我认为这是因为我缺少依赖项但需要帮助
谢谢
.php_cs
│ .travis.yml
│ autoload.php
│ composer.json
│ composer.lock
│ git_push.sh
│ index.php
│ phpunit.xml.dist
│ README.md
│ tree
│ tree.txt
│
├───docs
│ ├───Api
│ │ DefaultApi.md
│ │
│ └───Model
│
│
├───lib
│ │
│ │
│ ├───Api
│ │ │ │
│ └───Model
│
├───test
│ ├───Api
│ │ │
│ └───Model
│
│
└───vendor
检查 NYC
是否代表有效的机场代码(在我看来不是)。
<?php
require_once(__DIR__ . '/vendor/autoload.php');
$api_instance = new Swagger\Client\Api\DefaultApi();
$apikey = "jJtGVQ********************RONJZq1"; // string | API Key provided for your account, to identify you for API access. Make sure to keep this API key secret.
$origin = "NYC"; // string | <a href=\"https://en.wikipedia.org/wiki/International_Air_Transport_Association_airport_code\">IATA code</a> of the city from which the traveler will depart. See the location and airport interfaces for more information.
$destination = "LAX"; // string | <a href=\"https://en.wikipedia.org/wiki/International_Air_Transport_Association_airport_code\">IATA code</a> of the city to which the traveler is going
$departure_date = "2017-12-16--2017-12-26"; // string | Range of dates between which the traveler could depart. Dates are specified in the <a href=\"https://en.wikipedia.org/wiki/ISO_8601\">ISO 8601</a> yyyy-MM-dd date format. Ranges are inclusive and ranges of months will apply from the start to the end of the month. If just a single date is specified, only that date will be searched. By default, the date range starts today and applies up to 361 in the future is applied. Past dates are generally not supported, future dates should be in the next 361 days, although results start to become sparse after about 6 months in the future, as airlines may still be defining their schedules. The default is to search all future dates available.
$one_way = false; // bool | When set to true, the query will be for a single trip from the origin to the destination. When this parameter is not provided, or is set to false, the query is for a round trip from the origin to the destination and back again.
$duration = "1--15"; // string | The allowed duration or range of durations of the trip, in days. This parameter must not be set if the one-way parameter is set to true.
$direct = false; // bool | Limit the search to results that do not require the passenger to change plane?
$max_price = "100000"; // string | Maximum price of trips to find in the result set, in the currency specified for this origin and destination pair in the cache contents spreadsheet. So, for example, if the origin is NYC, and the max price is 400, this means 400 USD. If the origin is PAR, and the max price is 400, this means 400 EUR. By default, no limit is applied
$aggregation_mode = ""; // string | Specifies the granularity of results to be found. DESTINATION is the default and finds one result per city. COUNTRY finds one result per country, DAY finds on result for every day in the date range, WEEK finds one result for every week in the date range. Note that specifying a small granularity but a large search scope may result in a huge output. For some very large outputs, the API may refuse to provide a result.
try {
$result = $api_instance->flightInspirationSearch($apikey, $origin, $destination, $departure_date, $one_way, $duration, $direct, $max_price, $aggregation_mode);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling DefaultApi->flightInspirationSearch: ', $e->getMessage(), PHP_EOL;
}
?>
只是将 $one_way = false;
更改为 $one_way = "false";
基本上它不是采用布尔值而是采用字符串作为参数,即使 api 说的是布尔值,并且还对 $direct
我想准确地说 API 中没有错误,我刚刚使用 http 客户端进行了测试,查询参数 one_way 和direct 需要布尔类型而不是字符串,如果您尝试 "true" 或 "false" 值,您将收到错误的请求响应错误 (HTTPsatus = 400)。您可以使用 API.
的 shooter 自己尝试
问题很可能出现在构建最终 http 查询的 PHP 方法中,从布尔值到字符串的转换应该是错误的,因此您收到了 400 HTTP 错误。
我正在尝试开始使用 amadeus sandbox travel api
,并且刚刚开始使用 api
docs
<?php
require_once(__DIR__ . '/vendor/autoload.php');
$api_instance = new Swagger\Client\Api\DefaultApi();
$apikey = "jJtGVQ********************RONJZq1"; // string | API Key provided for your account, to identify you for API access. Make sure to keep this API key secret.
$origin = "NYC"; // string | <a href=\"https://en.wikipedia.org/wiki/International_Air_Transport_Association_airport_code\">IATA code</a> of the city from which the traveler will depart. See the location and airport interfaces for more information.
$destination = "LAX"; // string | <a href=\"https://en.wikipedia.org/wiki/International_Air_Transport_Association_airport_code\">IATA code</a> of the city to which the traveler is going
$departure_date = "2017-12-16--2017-12-26"; // string | Range of dates between which the traveler could depart. Dates are specified in the <a href=\"https://en.wikipedia.org/wiki/ISO_8601\">ISO 8601</a> yyyy-MM-dd date format. Ranges are inclusive and ranges of months will apply from the start to the end of the month. If just a single date is specified, only that date will be searched. By default, the date range starts today and applies up to 361 in the future is applied. Past dates are generally not supported, future dates should be in the next 361 days, although results start to become sparse after about 6 months in the future, as airlines may still be defining their schedules. The default is to search all future dates available.
$one_way = false; // bool | When set to true, the query will be for a single trip from the origin to the destination. When this parameter is not provided, or is set to false, the query is for a round trip from the origin to the destination and back again.
$duration = "1--15"; // string | The allowed duration or range of durations of the trip, in days. This parameter must not be set if the one-way parameter is set to true.
$direct = false; // bool | Limit the search to results that do not require the passenger to change plane?
$max_price = "100000"; // string | Maximum price of trips to find in the result set, in the currency specified for this origin and destination pair in the cache contents spreadsheet. So, for example, if the origin is NYC, and the max price is 400, this means 400 USD. If the origin is PAR, and the max price is 400, this means 400 EUR. By default, no limit is applied
$aggregation_mode = ""; // string | Specifies the granularity of results to be found. DESTINATION is the default and finds one result per city. COUNTRY finds one result per country, DAY finds on result for every day in the date range, WEEK finds one result for every week in the date range. Note that specifying a small granularity but a large search scope may result in a huge output. For some very large outputs, the API may refuse to provide a result.
try {
$result = $api_instance->flightInspirationSearch($apikey, $origin, $destination, $departure_date, $one_way, $duration, $direct, $max_price, $aggregation_mode);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling DefaultApi->flightInspirationSearch: ', $e->getMessage(), PHP_EOL;
}
?>
这是我用来执行搜索的示例代码 但它给我一个错误
调用时出现异常DefaultApi
flightInspirationSearch: [400] Error connecting to the API (https://api.sandbox.amadeus.com/v1.2/flights/inspiration-search?apikey=jJt*************************JZq1&origin=NYC&destination=LAX&departure_date=2017-12-16--2017-12-26&one-way=0&duration=1--15&direct=0&max_price=100000&aggregation_mode=)
如果有人能告诉我为什么会出现此错误,我将不胜感激,我实际上正在使用 xampp
在 windows 机器上进行本地测试 php > 7.0
我认为这是因为我缺少依赖项但需要帮助 谢谢
.php_cs
│ .travis.yml
│ autoload.php
│ composer.json
│ composer.lock
│ git_push.sh
│ index.php
│ phpunit.xml.dist
│ README.md
│ tree
│ tree.txt
│
├───docs
│ ├───Api
│ │ DefaultApi.md
│ │
│ └───Model
│
│
├───lib
│ │
│ │
│ ├───Api
│ │ │ │
│ └───Model
│
├───test
│ ├───Api
│ │ │
│ └───Model
│
│
└───vendor
检查 NYC
是否代表有效的机场代码(在我看来不是)。
<?php
require_once(__DIR__ . '/vendor/autoload.php');
$api_instance = new Swagger\Client\Api\DefaultApi();
$apikey = "jJtGVQ********************RONJZq1"; // string | API Key provided for your account, to identify you for API access. Make sure to keep this API key secret.
$origin = "NYC"; // string | <a href=\"https://en.wikipedia.org/wiki/International_Air_Transport_Association_airport_code\">IATA code</a> of the city from which the traveler will depart. See the location and airport interfaces for more information.
$destination = "LAX"; // string | <a href=\"https://en.wikipedia.org/wiki/International_Air_Transport_Association_airport_code\">IATA code</a> of the city to which the traveler is going
$departure_date = "2017-12-16--2017-12-26"; // string | Range of dates between which the traveler could depart. Dates are specified in the <a href=\"https://en.wikipedia.org/wiki/ISO_8601\">ISO 8601</a> yyyy-MM-dd date format. Ranges are inclusive and ranges of months will apply from the start to the end of the month. If just a single date is specified, only that date will be searched. By default, the date range starts today and applies up to 361 in the future is applied. Past dates are generally not supported, future dates should be in the next 361 days, although results start to become sparse after about 6 months in the future, as airlines may still be defining their schedules. The default is to search all future dates available.
$one_way = false; // bool | When set to true, the query will be for a single trip from the origin to the destination. When this parameter is not provided, or is set to false, the query is for a round trip from the origin to the destination and back again.
$duration = "1--15"; // string | The allowed duration or range of durations of the trip, in days. This parameter must not be set if the one-way parameter is set to true.
$direct = false; // bool | Limit the search to results that do not require the passenger to change plane?
$max_price = "100000"; // string | Maximum price of trips to find in the result set, in the currency specified for this origin and destination pair in the cache contents spreadsheet. So, for example, if the origin is NYC, and the max price is 400, this means 400 USD. If the origin is PAR, and the max price is 400, this means 400 EUR. By default, no limit is applied
$aggregation_mode = ""; // string | Specifies the granularity of results to be found. DESTINATION is the default and finds one result per city. COUNTRY finds one result per country, DAY finds on result for every day in the date range, WEEK finds one result for every week in the date range. Note that specifying a small granularity but a large search scope may result in a huge output. For some very large outputs, the API may refuse to provide a result.
try {
$result = $api_instance->flightInspirationSearch($apikey, $origin, $destination, $departure_date, $one_way, $duration, $direct, $max_price, $aggregation_mode);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling DefaultApi->flightInspirationSearch: ', $e->getMessage(), PHP_EOL;
}
?>
只是将 $one_way = false;
更改为 $one_way = "false";
基本上它不是采用布尔值而是采用字符串作为参数,即使 api 说的是布尔值,并且还对 $direct
我想准确地说 API 中没有错误,我刚刚使用 http 客户端进行了测试,查询参数 one_way 和direct 需要布尔类型而不是字符串,如果您尝试 "true" 或 "false" 值,您将收到错误的请求响应错误 (HTTPsatus = 400)。您可以使用 API.
的 shooter 自己尝试问题很可能出现在构建最终 http 查询的 PHP 方法中,从布尔值到字符串的转换应该是错误的,因此您收到了 400 HTTP 错误。