Reviews in Google API
Asked Answered
M

1

8

I am using below code to find Google reviews for property. What I am trying to do is, I am fetching review for property then I will compare it with old review of that property (which is in the DB). If it is greater than the system's property, then it sends email.

This file is run for every hour(as a cron file) and i enable the billing in Google API, so max limit is 1,50,000.

But for some reason API does not return the exact count of reviews. For example:
I run this file for the one property which has 4 reviews, but API returns 0 for 2 or 3 times then after some time it returns 4 reviews.

I don't know the reason behind it. I also noticed that we can see the reviews on google search page and in Google+. Same you can write reviews in multiple places, like in Google+ and in Google Map.

And to check reviews, I am using google plus url. So is it possible that the review does exist, but in another area(like in Google search page but not in Google+)?

/* call api to get review count of Google */
$url = "https://maps.googleapis.com/maps/api/place/details/json?";
$params = array(
    "placeid" => $google_place_id,
    "key" => $google_api_key
);
$url .= http_build_query($params);
$resjson = file_get_contents($url);
$msg = $resjson;
Yii::log($msg,'info', 'application');
$resjson = json_decode($resjson,true);

$review_count = $resjson['result']['user_ratings_total']=='' ? 0 : $resjson['result']['user_ratings_total'];
/* If review is greater than 0 then check old review and if it's not same then send email */
if($review_count>0)
{
    if(sizeof($ressql)>0)
    {
        /* if google plus review is greater then system's google+ review then send email */
        if($review_count>trim($ressql[0]['google_plus_review']))
        {
            $this->send_googleplusmail($prop_id);
            $msg = "Google+ Review for property id (Mail Sent):".$prop_id." , New Review:$review_count, Old Review: ".$ressql[0]['google_plus_review'];
            Yii::log($msg,'info', 'application');
        }
    }
}

$sql=" INSERT INTO tbl_review_alert (propertyid, google_plus_review) VALUES ";
$sql.="('{$prop_id}','{$review_count}')";
$sql.=" ON DUPLICATE KEY UPDATE propertyid= {$prop_id},google_plus_review= {$review_count}";
$this->insert_review($sql);

My Question is:
(1) Is it possible that the review does exist, but in another area(like in Google search page but not in Google+)? If yes, then in this case can i obtain the URL where review is posted?
(2) Are all of the reviews are sync in Google?
(3) Or i am doing something wrong in my code?

Mensal answered 17/4, 2015 at 6:19 Comment(4)
could you update your code with the place id that has inconsistent number of reviews, so that we can recreate?Nape
@Alexey, google place id is dynamic, the above problem is happening for multiple property. exa: https://plus.google.com/101511264527346460079/about and https://www.google.co.in/webhp?ie=utf-8&oe=utf-8&gws_rd=cr&ei=clA-VeieGIORuQSj54DwCw#q=The+Kensington+665+Washington+St+Boston%2C+MA+02111 you can see that on google+ there is no review. but in google search, you can see that there is 43 Google reviews for this property.Mensal
Just a side note, Google Places API can only show you max 5 reviews as from the doc (developers.google.com/places/webservice/details), reviews[] a JSON array of up to five reviews.Aplacental
@ilpaijin, yes i know that, that's why i am using user_ratings_total parameter. Which returns total no. of reviews.Mensal
A
5

I think I've spot where the problem is.

The reason why you can't see the existing reviews about that Place is that it seems that there're 2 google+ accounts for the same; The only difference (at least the first I've noticed) is in the zip code, MA 02116 vs. MA 02111.

Take a look at:

https://plus.google.com/101511264527346460079/about

and

https://plus.google.com/105917345931375838754/about

As you can see, in the second one there are the same reviews you see in the search page

And by inserting the address "The Kensington, 665 Washington St, Boston, MA 02116, Stati Uniti" into the finder, I obtain a placeid different from the other one.

Now by using this last one in

$params = array(
    "placeid" => $google_place_id, // the new placeid here
    "key" => $google_api_key
);

I can then get the 5 reviews in the Place API json response.

Aplacental answered 27/4, 2015 at 16:7 Comment(2)
thanks a lot. just curious, how you able to find that there is two google+ accounts?Mensal
You're welcome. However nothing special, I've just played around and noticed it.Aplacental

© 2022 - 2024 — McMap. All rights reserved.