【问题标题】:Filter reviews from the Google places API过滤来自 Google 地方 API 的评论
【发布时间】: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


【解决方案1】:

没有过滤 Places API 返回的评论集的选项。它会向您显示 Google 拥有的最有用的评论,就像您在 Google 地图上看到的一样。

因此您无法弄清楚,因为该选项不存在。作为参考,可用的选项是documented here on the Google Developers site

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-14
    • 2017-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多