Google 本地搜索结果超过 7 个?

发布于 2024-09-17 05:35:27 字数 2298 浏览 7 评论 0原文

目前我正在使用以下代码:

$zipcode = '91762';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://ajax.googleapis.com/ajax/services/search/local?v=1.0&q=restauraunts+".$zipcode."&rsz=large");
curl_setopt($ch, CURLOPT_HEADER, 0);
ob_start();
curl_exec($ch);
$data = ob_get_contents();
ob_end_clean();
curl_close($ch);
$restauraunts_array = json_decode($data, true);

        foreach($restauraunts_array['responseData']['results'] as $key => $value) {
            $results[] = array(
                'title' => $value['titleNoFormatting'],
                'address' => $value['streetAddress'],
                'city' => $value['city'],
                'state' => $value['region'],
                'zipcode' => $zipcode,
                'phone' => $value['phoneNumbers'][0]['number'],
                'lat' => $value['lat'],
                'lng' => $value['lng']
            );
        }

但它只会返回 7 个结果。我正在寻找一种方法来恢复更多。我查看了 API 代码,没有找到任何方法来获取更多结果。能做到吗?您能否指出如何获得多个结果的文档/实现?

回答:Mikey 能够提供我正在寻找的答案。以下是我为获得 32 个结果所做的操作:

 $zipcode = '91762';
    $results = array()
    $counter = array(0,8,16,24);
    foreach($counter as $page) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://ajax.googleapis.com/ajax/services/search/local?v=1.0&q=restauraunts+".$zipcode."&rsz=large&start=".$page);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    ob_start();
    curl_exec($ch);
    $data = ob_get_contents();
    ob_end_clean();
    curl_close($ch);
    $restauraunts_array = json_decode($data, true);
    if(!empty($restauraunts_array['responseData']['results'])) {
            foreach($restauraunts_array['responseData']['results'] as $key => $value) {
                $results[] = array(
                    'title' => $value['titleNoFormatting'],
                    'address' => $value['streetAddress'],
                    'city' => $value['city'],
                    'state' => $value['region'],
                    'zipcode' => $zipcode,
                    'phone' => $value['phoneNumbers'][0]['number'],
                    'lat' => $value['lat'],
                    'lng' => $value['lng']
                );
            }
      }
      return $results;

Currently I am using the following code:

$zipcode = '91762';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://ajax.googleapis.com/ajax/services/search/local?v=1.0&q=restauraunts+".$zipcode."&rsz=large");
curl_setopt($ch, CURLOPT_HEADER, 0);
ob_start();
curl_exec($ch);
$data = ob_get_contents();
ob_end_clean();
curl_close($ch);
$restauraunts_array = json_decode($data, true);

        foreach($restauraunts_array['responseData']['results'] as $key => $value) {
            $results[] = array(
                'title' => $value['titleNoFormatting'],
                'address' => $value['streetAddress'],
                'city' => $value['city'],
                'state' => $value['region'],
                'zipcode' => $zipcode,
                'phone' => $value['phoneNumbers'][0]['number'],
                'lat' => $value['lat'],
                'lng' => $value['lng']
            );
        }

But it will only return 7 results. I am looking for a way to get back many more. I have looked through the API code and have not found any methods to get more results back. Can it be done? Can you point me to the documentation / implementation of how to get more than a few results?

ANSWER: Mikey was able to provide the answer I was looking for. Here is what I am doing to get 32 results:

 $zipcode = '91762';
    $results = array()
    $counter = array(0,8,16,24);
    foreach($counter as $page) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://ajax.googleapis.com/ajax/services/search/local?v=1.0&q=restauraunts+".$zipcode."&rsz=large&start=".$page);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    ob_start();
    curl_exec($ch);
    $data = ob_get_contents();
    ob_end_clean();
    curl_close($ch);
    $restauraunts_array = json_decode($data, true);
    if(!empty($restauraunts_array['responseData']['results'])) {
            foreach($restauraunts_array['responseData']['results'] as $key => $value) {
                $results[] = array(
                    'title' => $value['titleNoFormatting'],
                    'address' => $value['streetAddress'],
                    'city' => $value['city'],
                    'state' => $value['region'],
                    'zipcode' => $zipcode,
                    'phone' => $value['phoneNumbers'][0]['number'],
                    'lat' => $value['lat'],
                    'lng' => $value['lng']
                );
            }
      }
      return $results;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

可是我不能没有你 2024-09-24 05:35:27

您目前在大多数方面都受到限制
案例总共 64 个结果 -
共 8 页,每页 8 个结果 -
您可以使用以下命令检索
搜索API。例外情况
规则是本地和博客。当地的
将返回最多 4 页,共 8 页
结果,总共 32 个,以及
博客将仅返回前 8 个。

来源:http: //groups.google.com/group/Google-AJAX-Search-API/browse_thread/thread/db6616286ce83ca0

You are currently limited in most
cases to a total of 64 results -
across 8 pages of 8 results each -
that you can retrieve with the
Search API. The exceptions to this
rule are Local and Blog. Local
will return up to 4 pages of 8
results, for a total of 32, and
Blog will return only the first 8.

source: http://groups.google.com/group/Google-AJAX-Search-API/browse_thread/thread/db6616286ce83ca0

老娘不死你永远是小三 2024-09-24 05:35:27

这是不正确的 - 4 页,每页 8 个结果绝对是您可以检索的最大数量。

本地搜索最多有 32 个结果 - 常规搜索最多有 64 个结果。

This isn't correct - 4 pages with 8 results each is definitely the maximum you can retrieve.

It's 32 results max for local search - 64 results is the max for regular search.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文