Google Places API:next_page_token错误 [英] Google Places API : next_page_token error

查看:122
本文介绍了Google Places API:next_page_token错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在收集有关商店位置的信息. 搜索是:

I'm gathering information on the location of stores. The search is:

<?php
...
$url='https://maps.googleapis.com/maps/api/place/search/json?key=[my_key]&location=40.420989,-3.706812&radius=1000030&=&sensor=false';
$body=file_get_contents($url);
...
?>

我没有问题地返回了Json,并指出还有另一页结果. 我会再打如下电话

I return a Json without problems, and indicates that there is another page of results. I'll be back to make another call as follows

<?php
...
$url2='https://maps.googleapis.com/maps/api/place/search/json?key=[my_key]&pagetoken=ClREAAAAQXKNHPVGCkTC_MdjSqi2T0KBDMWjEu4KF1Ylw1761Po-67AnNSp4zw0wXD4oocGpx4olSl4k2LyklJBl3mBF4VPmxp3IoOCHDRlXVmivaDsSEBuG_V1GvCH1gS5s0LCuy3EaFNXxUzzHhZ5ZRYNfeGHuqewR6Zk7&sensor=false';
$body=file_get_contents($url2);
...
?>

如果我在第二次通话中运行它,则会收到错误消息

If I run it with the second call I get an error

状态"-> INVALID_REQUEST

'status' -> INVALID_REQUEST

但是当我将ulr2浏览器粘贴到结果中时是正确的.

But when I paste the ulr2 browser in the result is correct.

我该如何解决?

谢谢

推荐答案

这与请求之间的时间安排有关,如果您一个接一个地立即运行它们,则页面令牌还无效,您必须在连续的请求之间等待几秒钟.

It has something to do with the timing between the requests, if you run them immediately one after the other, the pagetoken isn't valid yet, you have to wait a few seconds between consecutive requests.

这是因为google的许可条款不允许您一次获取所有结果并将其全部返回给用户.您应该执行用户操作以请求更多结果,这会增加几秒钟的延迟.

This is because google's license terms don't allow you to fetch all the results at once and return them all at once to the user. You should have a user action asking for more results, which adds a delay of a couple of seconds.

这篇关于Google Places API:next_page_token错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆