[英]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.