Connor Gutman
Connor Gutman

Reputation: 115

Filter reviews from the Google places API

I am trying to filter through reviews from the Google places API to only return good reviews (4-5 stars) and can't figure out how this would be done. Here's what I have so far:

<?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;
 }
 ?>

What I'd like to happen is to some how only call on a review that has a rating of 5 or 4 stars. I don't know how I'd go about doing this though, and I'm new to JSON and relatively new to PHP.

Thank you for your time, Connor Gutman

Upvotes: 1

Views: 2474

Answers (1)

spiv
spiv

Reputation: 2518

There's no option to filter the set of reviews the Places API returns. It will show you the most helpful reviews Google has, same as you'd see on Google Maps.

So you can't figure it out because the option doesn't exist. For reference, the available options are documented here on the Google Developers site.

Upvotes: 1

Related Questions