所有机场地点的Skyscanner API和使用CURL的Travel API [英] Skyscanner API for all airport locations and Travel API using CURL

查看:1183
本文介绍了所有机场地点的Skyscanner API和使用CURL的Travel API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从skyscanner API获取地理目录数据。我已阅读文档 http://business.skyscanner.net/portal/en-GB / Documentation / ApiOverview

I am trying to fetch geo catalogue data from skyscanner api. I have read documentation http://business.skyscanner.net/portal/en-GB/Documentation/ApiOverview

我已经创建了api键。我正在成功打击api,并获得与 http://business.skyscanner相同的结果.net / portal / en-GB / Documentation / FlightsLivePricingQuickStart

I have created api key. I am hitting api successfully and getting result same as on the http://business.skyscanner.net/portal/en-GB/Documentation/FlightsLivePricingQuickStart

我打: -

http: partners.api.skyscanner.net/apiservices/pricing/v1.0/?apiKey=KEY&country=IR=EUR&locale=en-IE&originplace=51.845159,-8.492835-latlong&destinationplace=DUB-iata&inbounddate= & outbounddate = 2016-08-10& adults = 1& locationschema = iata& cabinclass = Economy& preferDirects = true& grouppricing = true

需要数据(xml或json)与所有直达机场可用提供的城市。例如: -

But I need data(xml or json) with all direct flight airport available from provided city. like:-

          <Airports>
            <Airport
              Id="BIN"
              Name="Bamiyan"
              CountryId="AF"
              Location="67.823611, 34.804167"
              CityId="BINA" />
          </Airports>

这是可能得到这种类型的数据

Is this possible to get this type of data

推荐答案

在搜索很多,并与Skyscanner讨论后,我终于发现没有这样的api由他们提供

但我已成功实施 Travel API ,我知道很多人在搜索这个,所以我在这里张贴代码给所有的人:)

But I have successfully implemented the Travel API, I know many of you searching for this so I am posting code here for all of you :)

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 .= "&currency=" . $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));
}

这篇关于所有机场地点的Skyscanner API和使用CURL的Travel API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆