我想定期获取 Google 对 1000 多家酒店的用户评分。是否有任何 API 和任何其他方式我可以检索此数据。
我用以下代码做到了:
$ch = curl_init();
$params = json_encode(["textQuery" => "hotels in Alexandroupolis",]);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_URL, 'https://places.googleapis.com/v1/places:searchText');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: ' . 'application/json',
'X-Goog-Api-Key: ' . MyGoogleApiKey,
'X-Goog-FieldMask: ' . 'places.displayName,places.rating',
]);
$response = curl_exec($ch);
curl_close($ch);