我对这个模块和
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: