我使用python中的googleplacesapi来查找城市/城镇/地方(给定为位置)中的任何内容(以查询形式给出)。以下是我的代码片段:
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个,并且googlemaps在同一个查询中返回了20多个结果。如何检索所有结果?在
编辑:我添加了最后3行代码,试图在下一页上获得结果,但是我被抛出了无效的请求错误。在
谢谢你读我的问题。在
我发现出了什么问题。系统抛出无效的\u请求,因为next_page_令牌无效(在发出下一个\u page_令牌到它将生效之间有一个小的延迟b/w)。我编译了代码的前半部分(不包括最后三行),然后编译了最后三行代码,它成功了!!所以据我所知,延误是造成错误的原因。在
所以现在我要做的就是在最后一个if条件之前设置1-2秒的计时器。在
感谢所有对这个问题发表评论和回答的人。你们是这个社区的英雄。在
请检查此url:HERE
将PagerToken作为附加参数添加到HTTP请求url中,如下所示
复制粘贴这个网址在浏览器上仔细检查。另外,请仔细阅读文档url。干杯!在
相关问题 更多 >
编程相关推荐