【发布时间】:2015-08-23 17:36:39
【问题描述】:
我正在尝试过滤来自 Google 地方 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 相对较新。
感谢您的宝贵时间, 康纳·古特曼
【问题讨论】:
-
google的API不提供过滤机制吗?我没看,但如果不看会很奇怪。
-
据我所知,您可以过滤搜索,但不能过滤餐厅结果。那必须在我这边完成。 ://
-
我不知道结果如何,但为什么不跳过你不想要的东西呢?
if (notWhatI'mLookingFor) continue;
标签: php json google-places-api google-places