对于这个模块和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
我在这里完全迷失了,因为我无法访问该对象的详细信息。也许我缺少了一些东西,但是非常感谢我提供有关此问题的指导。
答案 0 :(得分:1)
如果您完全迷路,请阅读文档:)
来自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 []最多五个评论的JSON数组。如果语言参数 是在“地方详情”请求中指定的,则地方信息服务将 偏向结果以偏爱使用该语言撰写的评论。每 评论包括以下几个部分: