Skyscanner API 所有机场位置和 Travel API 使用 CURL
Skyscanner API for all airport locations and Travel API using CURL
我正在尝试从 skyscanner api 获取地理目录数据。我已阅读文档 http://business.skyscanner.net/portal/en-GB/Documentation/ApiOverview
我已经创建了 api 密钥。我成功地击中 api 并获得与 http://business.skyscanner.net/portal/en-GB/Documentation/FlightsLivePricingQuickStart
相同的结果
我正在打:-
但我需要数据(xml 或 json),其中包含从提供的城市提供的所有直飞机场。喜欢:-
<Airports>
<Airport
Id="BIN"
Name="Bamiyan"
CountryId="AF"
Location="67.823611, 34.804167"
CityId="BINA" />
</Airports>
是否可以获取此类数据
经过大量搜索和Skyscanner的讨论,我终于发现他们没有提供这样的api。
但是我已经成功实现了 Travel API,我知道你们中的很多人都在搜索这个,所以我在这里为你们所有人发布代码:)
I am calling below function using ajax:-
function flight_data() {
$varApiKey = '?apiKey=ADD_KEY_HERE';
$country_code = 'IR';
$originplace = '51.845159,-8.492835-latlong';
$curency = 'EUR';
$destination = 'DUB-iata';
$start_date = date('Y-m-d');
$dateOneMonth = strtotime($start_date);
//$end_date = date("Y-m-d", strtotime("+1 month", $dateOneMonth));
$end_date = '';
$audult = '1';
$cabinclass = 'Economy';
$locationschema = 'iata';
$grouppricing = $preferDirects = 'true';
$query = "&country=" . $country_code;
$query .= "¤cy=" . $curency;
$query .= "&locale=en-IE";
$query .= "&originplace=" . $originplace;
$query .= "&destinationplace=" . $destination;
$query .= "&inbounddate=" . $end_date;
$query .= "&outbounddate=" . $start_date;
$query .= "&adults=" . $audult;
$query .="&locationschema=" . $locationschema;
$query .="&cabinclass=" . $cabinclass;
$query .="&preferDirects=" . $preferDirects;
$query .="&grouppricing=" . $grouppricing;
$apiParamsUrl = "http://partners.api.skyscanner.net/apiservices/pricing/v1.0/" . $varApiKey . $query . "";
$apiParamsStr = parse_url($apiParamsUrl, PHP_URL_QUERY); // get the query string parametures
parse_str($apiParamsStr, $apiParamsArray); // parse into an array
// the api url. First we need to request for a session
$apiSessionUrl = 'http://partners.api.skyscanner.net/apiservices/pricing/v1.0';
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $apiSessionUrl);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded', 'Accept: application/json')); // make api return json data
curl_setopt($ch, CURLOPT_POST, count($apiParamsArray)); // set how many fiels
curl_setopt($ch, CURLOPT_POSTFIELDS, $apiParamsStr); // set the fields
// caputre the headers
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
//execute post
$response = curl_exec($ch);
// get the headers
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size);
$body = substr($response, $header_size);
//close connection
curl_close($ch);
// print_r($response);
// die();
// get the api session url
preg_match('~Location: ([^\s]+)~', $header, $matches);
$apiSessionUrl = $matches[1];
// add on the api key for the session
$apiSessionUrl .= $varApiKey;
// get the json data
$data = file_get_contents($apiSessionUrl);
// decode the json
$array = json_decode($data, true);
// dump json array`enter code here`
printf('<pre>Poll Data %s</pre>', print_r($array, true));
}
截至 2017 年 5 月。这会获取机场数据:
http://partners.api.skyscanner.net/apiservices/geo/v1.0?apiKey=aslkdjhfasdbfaodyf2309y232
当然要更改虚拟密钥。
这给了你 xml
如果你这样做,你会得到一个 json 转储:
卷曲 http://partners.api.skyscanner.net/apiservices/geo/v1.0?apiKey=aslkdjhfasdbfaodyf2309y232 > airports.json
我正在尝试从 skyscanner api 获取地理目录数据。我已阅读文档 http://business.skyscanner.net/portal/en-GB/Documentation/ApiOverview
我已经创建了 api 密钥。我成功地击中 api 并获得与 http://business.skyscanner.net/portal/en-GB/Documentation/FlightsLivePricingQuickStart
相同的结果我正在打:-
但我需要数据(xml 或 json),其中包含从提供的城市提供的所有直飞机场。喜欢:-
<Airports>
<Airport
Id="BIN"
Name="Bamiyan"
CountryId="AF"
Location="67.823611, 34.804167"
CityId="BINA" />
</Airports>
是否可以获取此类数据
经过大量搜索和Skyscanner的讨论,我终于发现他们没有提供这样的api。
但是我已经成功实现了 Travel API,我知道你们中的很多人都在搜索这个,所以我在这里为你们所有人发布代码:)
I am calling below function using ajax:-
function flight_data() {
$varApiKey = '?apiKey=ADD_KEY_HERE';
$country_code = 'IR';
$originplace = '51.845159,-8.492835-latlong';
$curency = 'EUR';
$destination = 'DUB-iata';
$start_date = date('Y-m-d');
$dateOneMonth = strtotime($start_date);
//$end_date = date("Y-m-d", strtotime("+1 month", $dateOneMonth));
$end_date = '';
$audult = '1';
$cabinclass = 'Economy';
$locationschema = 'iata';
$grouppricing = $preferDirects = 'true';
$query = "&country=" . $country_code;
$query .= "¤cy=" . $curency;
$query .= "&locale=en-IE";
$query .= "&originplace=" . $originplace;
$query .= "&destinationplace=" . $destination;
$query .= "&inbounddate=" . $end_date;
$query .= "&outbounddate=" . $start_date;
$query .= "&adults=" . $audult;
$query .="&locationschema=" . $locationschema;
$query .="&cabinclass=" . $cabinclass;
$query .="&preferDirects=" . $preferDirects;
$query .="&grouppricing=" . $grouppricing;
$apiParamsUrl = "http://partners.api.skyscanner.net/apiservices/pricing/v1.0/" . $varApiKey . $query . "";
$apiParamsStr = parse_url($apiParamsUrl, PHP_URL_QUERY); // get the query string parametures
parse_str($apiParamsStr, $apiParamsArray); // parse into an array
// the api url. First we need to request for a session
$apiSessionUrl = 'http://partners.api.skyscanner.net/apiservices/pricing/v1.0';
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $apiSessionUrl);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded', 'Accept: application/json')); // make api return json data
curl_setopt($ch, CURLOPT_POST, count($apiParamsArray)); // set how many fiels
curl_setopt($ch, CURLOPT_POSTFIELDS, $apiParamsStr); // set the fields
// caputre the headers
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
//execute post
$response = curl_exec($ch);
// get the headers
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $header_size);
$body = substr($response, $header_size);
//close connection
curl_close($ch);
// print_r($response);
// die();
// get the api session url
preg_match('~Location: ([^\s]+)~', $header, $matches);
$apiSessionUrl = $matches[1];
// add on the api key for the session
$apiSessionUrl .= $varApiKey;
// get the json data
$data = file_get_contents($apiSessionUrl);
// decode the json
$array = json_decode($data, true);
// dump json array`enter code here`
printf('<pre>Poll Data %s</pre>', print_r($array, true));
}
截至 2017 年 5 月。这会获取机场数据:
http://partners.api.skyscanner.net/apiservices/geo/v1.0?apiKey=aslkdjhfasdbfaodyf2309y232
当然要更改虚拟密钥。
这给了你 xml
如果你这样做,你会得到一个 json 转储:
卷曲 http://partners.api.skyscanner.net/apiservices/geo/v1.0?apiKey=aslkdjhfasdbfaodyf2309y232 > airports.json