gpt4 book ai didi

php - Google API 中的评论

转载 作者:可可西里 更新时间:2023-11-01 12:36:58 25 4
gpt4 key购买 nike

我正在使用以下代码来查找 Google 对酒店的评论。我想做的是,我正在获取对属性(property)的评论,然后将其与该属性(property)的旧评论(在数据库中)进行比较。如果它大于系统的属性,则发送电子邮件。

此文件每小时运行一次(作为 cron 文件)并且我在 Google API 中启用了计费,因此最大限制为 1,50,000。

但出于某种原因,API 不会返回准确的评论数。例如:
我为一个有 4 条评论的属性运行此文件,但 API 返回 0 2 或 3 次,然后在一段时间后返回 4 条评论。

我不知道背后的原因。我还注意到我们可以在谷歌搜索页面和 Google+ 中看到评论。同样,您可以在多个地方撰写评论,例如在 Google+ 和 Google map 中。

为了查看评论,我使用的是 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) 还是我的代码有问题?

最佳答案

我想我已经找到问题所在了。

您看不到有关该地方的现有评论的原因是,似乎有 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 条评论。

关于php - Google API 中的评论,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29691740/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com