在 Python 3 中使用 GooglePlaces 获取地点详细信息(特别是评论)
Fetching place details (specifically reviews) with GooglePlaces in Python 3
我对这个模块完全陌生,Python 总的来说,但我想在业余时间开始一些有趣的项目。
我有一个关于 Python 的 GooglePlaces 模块的具体问题 - 如何仅通过知道地点 ID 来检索地点的评论。
到目前为止我已经完成了...
from googleplaces import GooglePlaces, types, lang
google_places = GooglePlaces('API KEY')
query_result = google_places.get_place(place_id="ChIJB8wSOI11nkcRI3C2IODoBU0")
print(query_result) #<Place name="Starbucks", lat=48.14308250000001, lng=11.5782337>
print(query_result.get_details()) # Prints None
print(query_result.rating) # Prints the rating of 4.3
我完全迷失在这里,因为我无法访问该对象的详细信息。也许我遗漏了一些东西,但非常感谢通过我的问题提供的任何指导。
如果您完全迷失了,请阅读文档:)
示例来自 https://github.com/slimkrazy/python-google-places:
for place in query_result.places:
# Returned places from a query are place summaries.
# The following method has to make a further API call.
place.get_details()
# Referencing any of the attributes below, prior to making a call to
# get_details() will raise a googleplaces.GooglePlacesAttributeError.
print place.details # A dict matching the JSON response from Google.
现在看到您的代码存在问题了吗?
print(query_result.get_details()) # Prints None
应该是
query_result.get_details() # Fetch details
print(query_result.details) # Prints details dict
关于结果,Google Docs 指出:
reviews[] a JSON array of up to five reviews. If a language parameter
was specified in the Place Details request, the Places Service will
bias the results to prefer reviews written in that language. Each
review consists of several components:
我对这个模块完全陌生,Python 总的来说,但我想在业余时间开始一些有趣的项目。 我有一个关于 Python 的 GooglePlaces 模块的具体问题 - 如何仅通过知道地点 ID 来检索地点的评论。
到目前为止我已经完成了...
from googleplaces import GooglePlaces, types, lang
google_places = GooglePlaces('API KEY')
query_result = google_places.get_place(place_id="ChIJB8wSOI11nkcRI3C2IODoBU0")
print(query_result) #<Place name="Starbucks", lat=48.14308250000001, lng=11.5782337>
print(query_result.get_details()) # Prints None
print(query_result.rating) # Prints the rating of 4.3
我完全迷失在这里,因为我无法访问该对象的详细信息。也许我遗漏了一些东西,但非常感谢通过我的问题提供的任何指导。
如果您完全迷失了,请阅读文档:)
示例来自 https://github.com/slimkrazy/python-google-places:
for place in query_result.places:
# Returned places from a query are place summaries.
# The following method has to make a further API call.
place.get_details()
# Referencing any of the attributes below, prior to making a call to
# get_details() will raise a googleplaces.GooglePlacesAttributeError.
print place.details # A dict matching the JSON response from Google.
现在看到您的代码存在问题了吗?
print(query_result.get_details()) # Prints None
应该是
query_result.get_details() # Fetch details
print(query_result.details) # Prints details dict
关于结果,Google Docs 指出:
reviews[] a JSON array of up to five reviews. If a language parameter was specified in the Place Details request, the Places Service will bias the results to prefer reviews written in that language. Each review consists of several components: