Исключение при вызове DefaultApi-> flightInspirationSearch: [400] Ошибка подключения к API

Я пытаюсь начать с amadeus sandbox travel api и только начинается с api документы

  <?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] Ошибка подключения к API (https://api.sandbox.amadeus.com/v1.2/flights/inspiration-search?apikey=jJt************************* JZq1&Происхождение = Нью-Йорк&назначения = LAX&DEPARTURE_DATE = 2017-12-16—2017-12-26&в одну сторону = 0&Продолжительность = 1—15&прямой = 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

0

Решение

Проверить, если NYC представляет действительный код аэропорта (мне кажется, что нет).

0

Другие решения

 <?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

0

Я хотел бы уточнить, что в API нет ошибки, я только что проверил с помощью клиента http, параметры запроса в одну сторону а также непосредственный ожидают логический тип, а не строку; если вы попробуете значения «истина» или «ложь», вы получите ошибку ответа на неверный запрос (HTTPsatus = 400). Вы можете попробовать это самостоятельно, используя стрелок API.

Скорее всего, проблема заключается в вашем методе PHP, который создает окончательный http-запрос; должно быть неправильное преобразование из логического значения в строковое, поэтому вы получили ошибку HTTP 400.

0
По вопросам рекламы ammmcru@yandex.ru
Adblock
detector