Я пытаюсь получить данные airbnb, для этого я подключился к airbnb api, но моя проблема в конвертации в csv. Я скомпилировал код в Linux и сохранил результат в CSV-файл. Кто-нибудь знает, как я могу сделать это без беспорядка данных? Благодарю.
<?php
$limit = 50;
For($i=0, $offset = 0; $i < 100; $i++, $offset += $limit){
$url="https://api.airbnb.com/v2/search_results?client_id=3092nxybyb0otqw18e8nh5nty&locale=es-ES¤cy=EUR&_format=for_search_results&_limit=$limit&_offset=$offset&fetch_facets=true&guests=1&ib=false&ib_add_photo_flow=true&location=Las-Palmas-de-Gran-Canaria--Espa%25C3%25B1a&min_bathrooms=1&min_bedrooms=1&min_beds=1&min_num_pic_urls=0&price_max=1000&price_min=9&sort=1&user_lat=28.1132&user_lng=-15.4409";
$ci = curl_init();
curl_setopt_array( $ci, array(CURLOPT_URL => $url,CURLOPT_TIMEOUT => 3600, CURLOPT_RETURNTRANSFER => true));
$result = curl_exec($ci);
curl_close($ci);
$data = json_decode($result, true);
if(count($data['search_results']) == 0) die("No more listings");
foreach($data['search_results'] as $d) {
$id = $d['listing']['id'];
$urlita = "https://api.airbnb.com/v2/reviews?client_id=3092nxybyb0otqw18e8nh5nty&listing_id=$id&role=all";
$cii = curl_init();
curl_setopt_array( $cii, array(CURLOPT_URL => $urlita,CURLOPT_TIMEOUT => 3600, CURLOPT_RETURNTRANSFER => true));
$reviewResult = curl_exec($cii);
curl_close($cii);
$review = json_decode($reviewResult, true);
foreach($review['reviews'] as $r){
echo $r['author']['acceptance_rate'] . ";";
echo $r['author']['created_at'] . ";";
echo $r['author']['first_name'] . ";";
echo $r['author']['has_profile_pic'] . ";";
echo $r['author']['id'] . ";";
echo $r['author']['identity_mt_verified'] . ";";
echo $r['author']['identity_v2_verified'] . ";";
echo $r['author']['identity_verified'] . ";";
echo $r['author']['is_superhost'] . ";";
echo $r['author']['is_trip_host'] . ";";
echo $r['author']['picture_large_url'] . ";";
echo $r['author']['picture_url'] . ";";
echo $r['author']['recommendation_count'] . ";";
echo $r['author']['response_rate'] . ";";
echo $r['author']['response_time'] . ";";
echo $r['author']['reviewee_count'] . ";";
echo $r['author']['thumbnail_medium_url'] . ";";
echo $r['author']['thumbnail_url'] . ";";
echo $r['author_id'] . ";";
echo $r['can_be_edited'] . ";";
echo $r['comments'] . ";";
echo $r['created_at'] . ";";
echo $r['id'] . ";";
echo $r['listing_id'] . ";";
echo $r['recipient_id'] . ";";
echo "\n";
}
}
}
Задача ещё не решена.
Других решений пока нет …