过滤来自Google places API的评论


Filter reviews from the Google places API

我正试图过滤来自Google places API的评论,只返回好的评论(4-5星),但不知道如何做到这一点。以下是目前为止的内容:

<?php
 //Search variables
 $KEY='&key=YOURAPIKEY';
 $NAME='Pomegranate Cafe'; //business you are searching for
 $NAME= preg_replace("/['s_]/", "-", $NAME);
 $ADDRESS='4025 E Chandler Blvd Ste 28';  //business address
 $ADDRESS= preg_replace("/['s_]/", "-", $ADDRESS);
 $URL= 'https://maps.googleapis.com/maps/api/place/textsearch/json?query=';

 //Search through API for ID
 $searchJson = file_get_contents($URL.$NAME.$ADDRESS.$KEY);
 $searchJson = json_decode($searchJson, true);
 foreach ($searchJson['results'] as $place_id)
 {
     $googleID = $place_id['place_id'];
 };
 $URL= 'https://maps.googleapis.com/maps/api/place/details/json?placeid=' . $googleID . $KEY;
 $restaurantInfo = file_get_contents($URL);
 $restaurantInfo = json_decode($restaurantInfo, true);
 foreach ( $restaurantInfo['result']['reviews'][0] as $reviews )
 {   
     echo $reviews;
 }
 ?>

我想要发生的是如何只调用具有5星或4星评级的评论。我不知道该怎么做,我是JSON的新手,相对来说PHP还是新手。

谢谢你的时间,康纳古特曼

没有筛选Places API返回的评论集的选项。它会向你展示谷歌最有用的评论,就像你在谷歌地图上看到的一样。

所以你不能算出来,因为这个选项不存在。作为参考,可用的选项记录在这里的Google developer站点上。