Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
谷歌地图python下一页';行不通_Python_Google Maps_Google Places Api - Fatal编程技术网

谷歌地图python下一页';行不通

谷歌地图python下一页';行不通,python,google-maps,google-places-api,Python,Google Maps,Google Places Api,我通过谷歌地图库发送了一个请求,得到了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 maxi

我通过谷歌地图库发送了一个请求,得到了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())
它返回一个奇怪的错误

    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)
文件“/Users//testz.py”,第15行,在
打印gmaps.places(page_token=x['next_page_token'].encode())
包装器中的文件“/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site packages/googlemaps/client.py”,第356行
结果=函数(*args,**kwargs)
TypeError:places()至少接受2个参数(给定2个)
我使用.encode()是因为unicode和googlemaps中的“下一页”标记输出需要“str”


知道我做错了什么吗?如何修复它?

如果您再次传递所有参数(除了
页面\u标记
),它应该可以工作。请注意,您需要允许在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']

哦,那确实有效!谢谢!我很困惑,因为API的文档中说“设置pagetoken将导致忽略任何其他参数”。查询将执行与以前相同的搜索,但将返回一组新的结果“@nexla Yeah,page_token的文档不清楚。