使用PHP cUrl发出获取AirBnb日历的问题

时间:2016-09-04 02:34:53

标签: php json curl calendar airbnb

我正在尝试使用unofficial AirBnb API为我的客户列表获取airbnb日历。

API使用cUrl来检索日历:

curl -X POST --compressed 
-H "X-Airbnb-OAuth-Token: 9nwld6we4td9vkwj160teb49a" 
-H "Content-Type: application/json; charset=UTF-8" 
--data-binary '{"operations":[{"method":"GET","path":"/calendar_days","query":{"start_date":"2016-01-30","listing_id":"12132179","_format":"host_calendar","end_date":"2017-03-30"}},{"method":"GET","path":"/dynamic_pricing_controls/12132179","query":{}}],"_transaction":false}' 
https://api.airbnb.com/v2/batch/?client_id=3092nxybyb0otqw18e8nh5nty&locale=en-US&currency=USD

我使用Hurl.it对其进行了测试,所以我知道它有效。问题是我不知道使用PHP发送--data-binary部分的正确方法。我目前的PHP代码是:

$query = '{"operations":{"method":"GET","path":"/calendar_days","query":{"start_date":"' . date('Y-m-d') . '","listing_id":"' . $propertyID . '","_format":"host_calendar","end_date":"' . date('Y-m-d', strtotime('+1 year')) . '"}},"_transaction":false}';

$curl = curl_init();

curl_setopt_array($curl, array(
    CURLOPT_URL => "https://api.airbnb.com/v2/batch/?client_id=$client_id",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => [
        "Content-Type" => "application/json; charset=UTF-8",
        "X-Airbnb-OAuth-Token" => $token
    ],
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => $query
));

$calendar = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

非常感谢任何帮助。感谢。

1 个答案:

答案 0 :(得分:0)

尝试""

并将CURLOPT_BINARYTRANSFER设置为TRUE

(也可能设置X-Airbnb-API-Key:client_id_here)