使用CURL

时间:2017-02-16 09:48:37

标签: php api curl skyscanner

我正在尝试从skyscanner api获取地理目录数据。我看过文档 http://business.skyscanner.net/portal/en-GB/Documentation/ApiOverview

我创建了api密钥。我正在成功击中api并获得与之相同的结果 http://business.skyscanner.net/portal/en-GB/Documentation/HotelsLivePricingQuickStart

我正在打击: -

http://partners.api.skyscanner.net/apiservices/hotels/autosuggest/v2/UK/GBP/en-GB/。$ cityname.?apikey=prtl6749387986743898559646983194"

我希望得到JSON的回应。有可能??

我已成功获得航班实时价格,使用POST方法链接[Get error in using skyscanner Api of flight pricing in php

1 个答案:

答案 0 :(得分:0)

<?php
$checkin_date = "2017-05-05";
$checkout_date = "2017-05-08";
$guests = 10;
$rooms=  4;
$country_iso_code = "UK";
$country_currency = "EUR";
$locale_lang = "en-GB";
$url = "http://partners.api.skyscanner.net/apiservices/hotels/liveprices/v2/$country_iso_code/$country_currency/$locale_lang/27539733/$checkin_date/$checkout_date/$guests/$rooms?apiKey=prtl6749387986743898559646983194";

$ch = curl_init();
$http_header = ["Content_type : application/json"];
$options = [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTPHEADER => $http_header
];
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
curl_close($ch);

var_dump($response);

// Json中的响应

这只是基本的代码,你如何使用curl命中skyscanner的api来获取json格式的数据