gpt4 book ai didi

python - Python 中的 Google Places API

转载 作者:太空宇宙 更新时间:2023-11-04 09:44:01 36 4
gpt4 key购买 nike

我正在使用 python 中的 Google Places API 来查找城市/城镇/地点(作为位置给出)中的任何内容(作为查询给出)。以下是我的代码片段:

from googleplaces import GooglePlaces, types, lang


YOUR_API_KEY = 'xxxx'
google_places = GooglePlaces(YOUR_API_KEY)

query_result = google_places.text_search(
query='Play Schools', location = 'Mumbai, India')
print(len(query_result.places))
for place in query_result.places:
print (place.name)
print (place.place_id)
print('\n')

if (query_result.has_next_page_token):
query_result_next_page = google_places.text_search(
pagetoken=query_result.next_page_token)

现在的问题是我的代码将结果数限制为 20,而 Google map 在同一个查询中返回的结果超过 20 个。我该如何检索所有结果?

编辑:我添加了最后 3 行代码以尝试在下一页上获取结果,但出现 INVALID_REQUEST 错误。

感谢阅读我的问题。

最佳答案

By default, each Nearby Search or Text Search returns up to 20 establishment results per query; however, each search can return as many as 60 results, split across three pages. If your search will return more than 20, then the search response will include an additional value — next_page_token. Pass the value of the next_page_token to the pagetoken parameter of a new search to see the next set of results. If the next_page_token is null, or is not returned, then there are no further results. There is a short delay between when a next_page_token is issued, and when it will become valid. Requesting the next page before it is available will return an INVALID_REQUEST response. Retrying the request with the same next_page_token will return the next page of results.

检查此网址:HERE

像这样添加 PagerToken 作为 HTTP 请求 url 的附加参数

https://maps.googleapis.com/maps/api/place/nearbysearch/json?pagetoken=CpQCAgEAAFxg8o-eU7_uKn7Yqjana-HQIx1hr5BrT4zBaEko29ANsXtp9mrqN0yrKWhf-y2PUpHRLQb1GT-mtxNcXou8TwkXhi1Jbk-ReY7oulyuvKSQrw1lgJElggGlo0d6indiH1U-tDwquw4tU_UXoQ_sj8OBo8XBUuWjuuFShqmLMP-0W59Vr6CaXdLrF8M3wFR4dUUhSf5UC4QCLaOMVP92lyh0OdtF_m_9Dt7lz-Wniod9zDrHeDsz_by570K3jL1VuDKTl_U1cJ0mzz_zDHGfOUf7VU1kVIs1WnM9SGvnm8YZURLTtMLMWx8-doGUE56Af_VfKjGDYW361OOIj9GmkyCFtaoCmTMIr5kgyeUSnB-IEhDlzujVrV6O9Mt7N4DagR6RGhT3g1viYLS4kO5YindU6dm3GIof1Q&key=YOUR_API_KEY

将此网址复制粘贴到浏览器中并仔细检查。另外,请仔细阅读文档 url。干杯!

关于python - Python 中的 Google Places API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50504897/

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