我必须从Google地图API获取评论。详情请见本页。
https://developers.google.com/places/documentation/details#PlaceDetailsResults
详细信息将从此页面获取: -
我的问题是我无法找到请求中的引用内容。以及我如何从Google plus页面中找到此参数值。
答案 0 :(得分:17)
最近的一种方法:
{
"html_attributions": [],
"result": {
...
"rating": 4.6,
"reviews": [
{
"author_name": "John Smith",
"author_url": "https://www.google.com/maps/contrib/106615704148318066456/reviews",
"language": "en",
"profile_photo_url": "https://lh4.googleusercontent.com/-2t1b0vo3t-Y/AAAAAAAAAAI/AAAAAAAAAHA/0TUB0z30s-U/s150-c0x00000000-cc-rp-mo/photo.jpg",
"rating": 5,
"relative_time_description": "in the last week",
"text": "Great time! 5 stars!",
"time": 1508340655
}
]
}
}
响应:
There are 5 users currently playing League of Legends.
评论仅限于最新的5个。
答案 1 :(得分:5)
要获取Google评论,您需要该地方的参考ID。要获得此参考密钥,您可以使用google places search api request。
它的回复将包含您可以在请求中使用的引用ID。
<PlaceSearchResponse>
<status>OK</status>
<result>
<name>Koshy's Restaurant</name>
<type>bar</type>
<type>restaurant</type>
<type>food</type>
<type>establishment</type>
<formatted_address>
39, St Marks Road,Shivajinagar,Bangalore, Karnataka, 560001, India
</formatted_address>
<geometry>
<rating>3.7</rating>
<icon>
http://maps.gstatic.com/mapfiles/place_api/icons/bar-71.png
</icon>
**<reference>**
CnRwAAAA1z8aCeII_F2wIVcCnDVPQHQi5zdd-3FsDl6Xhb_16OGrILvvvI4X4M8bFk2U8YvuDCKcFBn_a2rjvYDtvUZJrHykDAntE48L5UX9hUy71Z4n80cO7ve_JXww6zUkoisfFnu6jEHcnKeeTUE42PCA4BIQGhGz0VrXWbADarhKwCQnKhoUOR-Xa9R6Skl0TZmOI4seqt8rO8I
**</reference>**
<id>2730db556ca6707ef517e5c165adda05d2395b90</id>
<opening_hours>
<open_now>true</open_now>
</opening_hours>
<html_attribution>
<a href="https://plus.google.com/116912222767108657277">Ujaval Gandhi</a>
</html_attribution>
</photo>
</result>
答案 2 :(得分:3)
$reqUri = 'https://maps.googleapis.com/maps/api/place/nearbysearch/json?key='.YOURSERVERKEY;
$reqUri .= '&sensor=false&radius=500';
$reqUri .= '&location=38.908310,-104.784035&name='.urlencode(LOCATION NAME);
$reqUri .= '&keyword='.urlencode(WEBSITE PHONE);
我是通过PHP制作的,现在调用此URL,您可以使用引用键获得原始结果。
然后解析它:
$data = cURL($reqUri);
$data = json_decode($data);
echo $data ->results[0]->reference;
希望它能帮到你
***注意:位置= 38.908310,-104.784035这个var不是自动你必须拥有它。
答案 3 :(得分:1)
使用Python和Google Places API,您可以按以下方式检索商户详细信息和评论(最多5条评论):
api = GooglePlaces("Your API key")
places = api.search_places_by_coordinate("40.819057,-73.914048", "100", "restaurant")
for place in places:
details = api.get_place_setails(place['place_id'], fields)
try:
website = details['result']['website']
except KeyError:
website = ""
try:
name = details['result']['name']
except KeyError:
name = ""
try:
address = details['result']['formatted_address']
except KeyError:
address = ""
try:
phone_number = details['result']['international_phone_number']
except KeyError:
phone_number = ""
try:
reviews = details['result']['reviews']
except KeyError:
reviews = []
print("===================PLACE===================")
print("Name:", name)
print("Website:", website)
print("Address:", address)
print("Phone Number", phone_number)
print("==================REVIEWS==================")
for review in reviews:
author_name = review['author_name']
rating = review['rating']
text = review['text']
time = review['relative_time_description']
profile_photo = review['profile_photo_url']
print("Author Name:", author_name)
print("Rating:", rating)
print("Text:", text)
print("Time:", time)
print("Profile photo:", profile_photo)
print("-----------------------------------------")
有关此代码和Google Places API的更多详细信息,您可以查看本教程:https://python.gotrained.com/google-places-api-extracting-location-data-reviews/
答案 4 :(得分:0)
我在本地主机上运行时遇到了问题。我添加了我的 example.com.test 域,但当然我无法验证它,因为它无法从外部访问(ngrok 变体除外)。
我在 GitHub 上发现了一个惊人的肮脏黑客:gaffling/PHP-Grab-Google-Reviews。
非常适合我,除了我必须将 /* CHECK SORT */
行更改为 if (isset($option['sort_by_reating_best_1']) and $option['sort_by_reating_best_1'] == true)
并且我还通过可选的第二个函数参数将 foreach 限制为仅 5 条评论。