gpt4 book ai didi

python - 在 Python 3 中使用 GooglePlaces 获取地点详细信息(特别是评论)

转载 作者:太空宇宙 更新时间:2023-11-03 11:38:59 24 4
gpt4 key购买 nike

总体而言,我对这个模块和 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 3 中使用 GooglePlaces 获取地点详细信息(特别是评论),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53723406/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com