Home » Php » php – Reviews in Google API

php – Reviews in Google API

Posted by: admin July 12, 2020 Leave a comment

Questions:

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?

How to&Answers:

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.