[英]Reviews in Google API
我正在使用下面的代码来查找Google对物业的评论。 我想做的是,我正在获取属性的评论,然后将其与该属性的旧评论(在数据库中)进行比较。 如果它大于系统的属性,则它将发送电子邮件。
该文件每小时运行一次(作为cron文件),并且我在Google API中启用了结算功能,因此最大限额为1,50,000。
但是由于某些原因,API不会返回确切的评论数。 例如:
我为具有4条评论的一个属性运行此文件,但是API返回0表示2或3次,然后在一段时间后返回4条评论。
我不知道背后的原因。 我还注意到,我们可以在Google搜索页和Google+中看到评论。 同样,您可以在多个地方(例如Google+和Google Map)中撰写评论。
并查看评论,我使用的是Google加网址。 因此,该评论确实可能存在,但存在于另一个区域(例如Google搜索页中,但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);
我的问题是:
(1)该评论是否确实存在,但是存在于另一个区域(例如Google搜索页中,但Google+中不存在)? 如果是,那么在这种情况下,我可以获取张贴评论的URL吗?
(2)是否所有评论都已在Google中同步?
(3)还是我的代码做错了什么?
我想我已经找到问题所在了。
之所以看不到该地点的现有评论,是因为似乎有2个google +帐户用于同一地点; 唯一的区别(至少我第一次注意到)是邮政编码MA 02116与MA 02111。
看一眼:
https://plus.google.com/101511264527346460079/关于
和
https://plus.google.com/105917345931375838754/关于
如您所见,在第二篇中,您在搜索页面中看到的评论相同
通过将地址“ The Kensington,665 Washington St,Boston,MA 02116,Stati Uniti”插入到取景器中 ,我得到了一个不同于另一个的Placeid。
现在通过使用最后一个
$params = array(
"placeid" => $google_place_id, // the new placeid here
"key" => $google_api_key
);
然后,我可以在Place API json响应中获得5条评论。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.