Google 地图 python next_page_token 不起作用
Google maps python next_page_token doesn't work
我通过 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)
然后我想请求第二页,我想我使用它是正确的。
print gmaps.places(page_token=x['next_page_token'].encode())
它 returns 一个奇怪的错误
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)
我使用 .encode() 因为 'next_page_token' unicode 输出和 googlemaps 需要 'str'.
知道我做错了什么吗?我该如何解决?
如果您再次传递所有参数(除了 page_token
),它应该可以工作。请注意,您需要 add a couple of seconds delay 才能在 Google 的服务器上验证令牌。
import googlemaps
import time
k="your key here"
gmaps = googlemaps.Client(key=k)
params = {
'query': ['restaurants', 'bakery', 'cafe', 'food'],
'location': (40.758896, -73.985130),
'radius': 10000
}
x = gmaps.places(**params)
print len(x['results']) # outputs 20 (which is maximum per 1 page result)
print x['results'][0]['name']
params['page_token'] = x['next_page_token']
time.sleep(2)
x1 = gmaps.places(**params)
print len(x1['results'])
print x1['results'][0]['name']
我通过 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)
然后我想请求第二页,我想我使用它是正确的。
print gmaps.places(page_token=x['next_page_token'].encode())
它 returns 一个奇怪的错误
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)
我使用 .encode() 因为 'next_page_token' unicode 输出和 googlemaps 需要 'str'.
知道我做错了什么吗?我该如何解决?
如果您再次传递所有参数(除了 page_token
),它应该可以工作。请注意,您需要 add a couple of seconds delay 才能在 Google 的服务器上验证令牌。
import googlemaps
import time
k="your key here"
gmaps = googlemaps.Client(key=k)
params = {
'query': ['restaurants', 'bakery', 'cafe', 'food'],
'location': (40.758896, -73.985130),
'radius': 10000
}
x = gmaps.places(**params)
print len(x['results']) # outputs 20 (which is maximum per 1 page result)
print x['results'][0]['name']
params['page_token'] = x['next_page_token']
time.sleep(2)
x1 = gmaps.places(**params)
print len(x1['results'])
print x1['results'][0]['name']