相关疑难解决方法(0)

在Google Places API上进行分页会返回状态INVALID_REQUEST

我正在使用Google Place API进行地点搜索:

https://developers.google.com/places/documentation/search

在第一次查询api之后,我通过设置pagetoken来获取下一页.如果我在请求之间等待2秒,它会起作用,但我注意到如果我在前一个查询之后立即进行下一个查询,它将返回状态INVALID_REQUEST.

这是某种限速吗?我在文档中的任何地方都没有看到这一点.

https://developers.google.com/places/usage

由于每个请求有20个位置,因此获取100个结果的列表将花费超过10秒,这对于某人等待使用应用程序来说是很长的.

google-maps rate-limiting google-places-api

9
推荐指数
2
解决办法
4377
查看次数

谷歌地图 python next_page_token 不起作用

我通过 google 地图库发送请求,得到 20 个地点的结果。

我的代码看起来像这样

gmaps = googlemaps.Client(key='MY_KEY_IS_HERE')

x = gmaps.places(query=['restaurants', 'bakery', 'cafe', 'food'],location='40.758896, -73.985130',radius=10000)

print len(x['results']) # outputs 20 (which is maximum per 1 page result)
Run Code Online (Sandbox Code Playgroud)

之后我想请求第二页,我认为我正确地使用了它。

print gmaps.places(page_token=x['next_page_token'].encode())
Run Code Online (Sandbox Code Playgroud)

它返回一个奇怪的错误

    File "/Users/././testz.py", line 15, in <module>
    print gmaps.places(page_token=x['next_page_token'].encode())
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/googlemaps/client.py", line 356, in wrapper
    result = func(*args, **kwargs)
TypeError: places() takes at least 2 arguments (2 given)
Run Code Online (Sandbox Code Playgroud)

我使用 .encode() 因为 unicode 中的“next_page_token”输出需要“str”。

知道我做错了什么以及如何解决它吗?

python google-maps google-places-api

5
推荐指数
1
解决办法
2388
查看次数