【问题标题】:Reviews in Google APIGoogle API 中的评论
【发布时间】: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/abouthttps://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


【解决方案1】:

我想我已经发现了问题所在。

您看不到有关该地点的现有评论的原因是似乎有 2 个 google+ 帐户相同;唯一的区别(至少我注意到的第一个区别)在于邮政编码,MA 02116 与 MA 02111。

看看:

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

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

如您所见,第二个中的评论与您在第二个中看到的评论相同 search page

通过将地址“The Kensington, 665 Washington St, Boston, MA 02116, Stati Uniti”插入the finder,我得到了一个与另一个不同的placeid。

现在在

中使用最后一个
$params = array(
    "placeid" => $google_place_id, // the new placeid here
    "key" => $google_api_key
);

然后我可以在 Place API json 响应中获得 5 条评论。

【讨论】:

  • 非常感谢。只是好奇,你怎么能找到有两个 google+ 帐户?
  • 不客气。不过没什么特别的,我只是玩了一下就注意到了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-08
  • 1970-01-01
  • 2013-05-01
  • 2015-06-26
  • 2019-02-17
  • 1970-01-01
相关资源
最近更新 更多