【发布时间】:2015-04-17 06:19:02
【问题描述】:
我正在使用下面的代码来查找 Google 对属性的评论。我想要做的是,我正在获取属性的评论,然后我会将它与该属性的旧评论(在数据库中)进行比较。如果大于系统属性,则发送邮件。
此文件每小时运行一次(作为 cron 文件),并且我在 Google API 中启用了计费,因此最大限制为 1,50,000。
但由于某种原因,API 不会返回准确的评论数。
例如:
我为一个有 4 条评论的属性运行此文件,但 API 2 或 3 次返回 0,然后在一段时间后返回 4 条评论。
我不知道背后的原因。我还注意到我们可以在谷歌搜索页面和谷歌+中看到评论。同样,您可以在多个地方撰写评论,例如在 Google+ 和 Google 地图中。
为了查看评论,我使用的是 google plus url。那么有没有可能该评论确实存在,但在另一个区域(例如在 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) 或者我的代码做错了什么?
【问题讨论】:
-
能否将您的代码更新为评论数不一致的地点 ID,以便我们重新创建?
-
@Alexey,google place id 是动态的,上述问题发生在多个属性上。例如:
https://plus.google.com/101511264527346460079/about和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你可以在 google+ 上看到没有评论。但在 google 搜索中,您可以看到该属性有 43 条 Google 评论。 -
附带说明,Google Places API 最多只能显示来自文档 (developers.google.com/places/webservice/details) 的 5 条评论,reviews[] 最多包含 5 条评论的 JSON 数组。
-
@ilpaijin,是的,我知道,这就是我使用
user_ratings_total参数的原因。返回总数。评论。
标签: php google-places-api google-plus-one