# Google 网页搜索 API

> 按关键词取一页 Google 搜索结果，和该国用户看到的一致：自然结果（标题、链接、摘要、排名）、广告、AI 概览、「其他人还问了」、相关搜索和知识面板。每次一页，约 10 条；用 page 翻页。

网页版：https://okdata.online/zh/apis/google/search/

- **接口**：`GET /v1/google/search`
- **ID**：`google.search`
- **价格**：$0.01/次
- **返回**：一个 Serp 对象（`data.item`）
- **状态**：预览
- **适合**：内容调研、竞品监控

## 价格

每次调用 $0.01，返回一个结果。查 1,000 次共 $10.00。请求到了平台的查询，查不到或出错也照常计费；还没请求到平台就被拦下的不扣费。

## 参数

| 参数名 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| `query` | string | 是 |  | 关键词，和在平台搜索框里输入的一样。（例：`best running shoes`） |
| `country` | string | 否 |  | 从哪个国家搜，两位国家代码（us、gb、de、jp……），结果按这个国家本地化；不填用 Google 默认。（例：`us`） |
| `language` | string | 否 |  | 界面语言，两位语言代码（en、fr、zh-cn……）。（例：`en`） |
| `location` | string | 否 |  | 从哪个地点搜（城市、地区、国家），用于本地化结果。（例：`Austin, Texas, United States`） |
| `page` | integer | 否 | `1` | 第几页，从 1 开始（1 到 10）。（例：`1`） |
| `view` | string: brief / compact / standard / full | 否 | `standard` | 返回多少字段。brief：只给 ID、标题、正文前 100 字、链接、时间和主要数字，适合先扫一遍列表，再按 ID 取详情；compact 去掉空字段、长正文截到 500 字；full 会在 ext 里带上平台特有字段。 |
| `fields` | string[] | 否 |  | 只保留这些字段，按路径写（如 author.name），用来省 token。放在查询参数里时用逗号分隔。 |

cursor、view、fields 的用法见 [请求说明](https://okdata.online/zh/docs/requests/)。

## 返回字段

每一条都是一个 [Serp](https://okdata.online/zh/docs/objects/serp/)。

| 字段 | 类型 | 说明 |
|---|---|---|
| `query` | string | 搜索词。 |
| `page` | integer | 第几页，从 1 开始。 |
| `total_results` | integer \| null | Google 自己估计的结果数。 |
| `organic` | SerpResult[] | 自然搜索结果，按页面顺序（通常最多 10 条）。 |
| `ads` | SerpAd[] | 页面上的付费结果；没有广告时为空。 |
| `ai_overview` | string \| null | AI 概览的文字（Google 随页面给出的话）；没有或另行加载时为 null。 |
| `related_questions` | string[] | 「其他人还问了」里的问题。 |
| `related_searches` | string[] | 页面底部的「相关搜索」。 |
| `knowledge_panel` | KnowledgePanel \| null | 知识面板：搜索词是 Google 认识的实体时才有，否则为 null。 |
| `ext` | object | 平台特有字段，只在 view=full 时返回。 |

## 请求示例

### cURL

```bash
curl -G "https://api.okdata.online/v1/google/search" \
  -H "Authorization: Bearer $OKDATA_API_KEY" \
  --data-urlencode 'query=best running shoes'
```

### Python

```python
import os
import requests

resp = requests.get(
    "https://api.okdata.online/v1/google/search",
    headers={"Authorization": f"Bearer {os.environ['OKDATA_API_KEY']}"},
    params={"query": "best running shoes"},
    timeout=60,
)
body = resp.json()
if body["code"] != "ok":
    raise RuntimeError(f"{body['code']}: {body['message']} (charged: {body['charged']})")

row = body["data"]["item"]
print(row)
print("cost: $" + body["meta"]["billing"]["amount"])
```

### TypeScript

```ts
const url = new URL('https://api.okdata.online/v1/google/search');
url.searchParams.set('query', "best running shoes");

const res = await fetch(url, {
  headers: {
    Authorization: `Bearer ${process.env.OKDATA_API_KEY}`,
  },
});
const body = await res.json();
if (body.code !== 'ok') throw new Error(`${body.code}: ${body.message}`);

const row = body.data.item;
console.log(row);
console.log('cost: $' + body.meta.billing.amount);
```

### MCP

```json
{
  "name": "call",
  "arguments": {
    "capability": "google.search",
    "query": "best running shoes"
  }
}
```

或者对接好 MCP 的智能体直接说：

> 用「Google 网页搜索」查一下，总结返回的结果。

## 返回示例

```json
{
  "code": "ok",
  "request_id": "0f6c2a8e-4b1d-4e0a-9a51-3c7d2b9e1f20",
  "data": {
    "item": {
      "query": "best running shoes",
      "page": 1,
      "total_results": 115,
      "organic": [
        {
          "rank": 1,
          "title": "The 7 Best Running Shoes of 2026, Tested",
          "url": "https://www.example.com/best-running-shoes",
          "displayed_url": "https://www.example.com › guides",
          "source": "Example Running",
          "snippet": "We ran 400 miles in 30 pairs to find the best daily trainers, racers and stability shoes.",
          "date": null
        }
      ],
      "ads": [
        {
          "rank": 1,
          "position": "top",
          "title": "Compare Running Shoes | Free Returns",
          "url": "https://www.example-shop.com/running",
          "displayed_url": "www.example-shop.com/running",
          "snippet": "Shop 200+ running shoes from top brands. Free shipping over $50."
        }
      ],
      "ai_overview": "The best running shoe depends on your stride, terrain and workouts.",
      "related_questions": [
        "What are the best types of shoes to run in?"
      ],
      "related_searches": [
        "best running shoes for men"
      ],
      "knowledge_panel": {
        "title": "Tesla, Inc.",
        "type": "Automotive company",
        "description": "Tesla, Inc. is an American multinational automotive and clean energy company.",
        "website": "https://www.tesla.com",
        "image_url": null
      }
    }
  },
  "warnings": [],
  "meta": {
    "capability": "google.search",
    "result_status": "complete",
    "billing": {
      "amount": "0.01",
      "currency": "USD",
      "balance_after": "9.99"
    },
    "unavailable": {},
    "cached": false,
    "replayed": false,
    "fetched_at": "2026-11-11T08:00:00Z"
  }
}
```

## 错误

所有错误同一种结构：code、request_id、message 和 message_zh（每个 code 一句固定的话）、charged、retry、retry_after_seconds、param 和 docs_url，具体问题写在 problems 里。请求到了平台的调用出错（查不到、平台失败或超时）时，按这个接口的价格计一次费，charged 为 true，并给出 amount；参数错误这类还没请求到平台的错误不扣费。只有 settlement_unknown 的扣费结果要查询后才知道。完整列表：https://okdata.online/zh/docs/errors/

## 常见问题

### Google 网页搜索接口多少钱？

每次调用 $0.01，返回一个结果。查 1,000 次共 $10.00。请求到了平台的查询，查不到或出错也照常计费；还没请求到平台就被拦下的不扣费。

### 需要Google账号、Cookie 或扫码登录吗？

不需要。只要带上 okdata 的 API key。返回的是Google上的公开数据，不会用到你自己的Google账号。

### 调用失败会扣费吗？

请求到了平台就会扣一次：返回为空、查不到、平台出错或超时，都按一次调用计费（按条计价的按 1 条），错误里 charged 为 true，并给出 amount。参数错误、余额不足这类还没请求到平台就被拦下的不扣费。

### Google不展示某个字段怎么办？

这个字段会是 null，meta.unavailable 里会列出它和原因：platform（平台本来就不展示）或 capability（我们暂时取不到）。

## Google的其他接口

- [Google 广告透明中心广告主搜索](https://okdata.online/zh/apis/google/advertisers/search/)：$0.004/次 · 每页约 10 个广告主
- [Google 广告主的广告](https://okdata.online/zh/apis/google/advertisers/ads/list/)：$0.004/次 · 每页约 40 条广告
- [Google 新闻搜索](https://okdata.online/zh/apis/google/news/search/)：$0.005/次 · 每页约 100 条结果
- [Google 图片搜索](https://okdata.online/zh/apis/google/images/search/)：$0.01/次 · 每页约 20 条结果
- [Google 购物搜索](https://okdata.online/zh/apis/google/shopping/search/)：$0.01/次 · 每页约 40 个商品
- [Google 地图商户搜索](https://okdata.online/zh/apis/google/maps/places/search/)：$0.005/次 · 每页约 20 条结果
- [Google 趋势：当下热搜](https://okdata.online/zh/apis/google/trends/trending/list/)：$0.008/次 · 每页约 100 条榜单
- [Google 搜索联想词](https://okdata.online/zh/apis/google/suggestions/list/)：$0.008/次 · 每页约 15 条榜单
- [Google 视频搜索](https://okdata.online/zh/apis/google/videos/search/)：$0.008/次
- [Google 学术搜索](https://okdata.online/zh/apis/google/scholar/search/)：$0.008/次
- [Google 专利搜索](https://okdata.online/zh/apis/google/patents/search/)：$0.008/次
- [Google 招聘搜索](https://okdata.online/zh/apis/google/jobs/search/)：$0.008/次 · 每页约 10 条结果

## 概要

- **简称**：网页搜索
- **英文名**：Google web search API
- **也叫**：谷歌搜索、Google 搜索接口、SERP、搜索排名、网页搜索
- **分类**：[社交媒体](https://okdata.online/zh/categories/social/)
- **状态**：预览。还可能调整，改动会提前公告。
- **价格**：$0.01（约 ¥0.071） / 次 · 参数错误不扣费
- **返回**：一个 Serp，放在 data.item 里
- **调用出错时**：照常计一次费。出错时我们这边先自动重试。请求到了平台的调用，出错也按一次计费；参数错误不扣费。

## 什么时候收费

- 返回了数据：$0.01，每次调用收一次
- 参数不合法、余额不足、接口暂停：不收费

| 情况 | 收费 |
|---|---|
| 单次最高扣费 | $0.01 |
| 空结果 | $0.01 |
| 查无此项（平台上没有） | $0.01 |
| 平台出错或超时 | $0.01 |
| 参数不合法、余额不足、接口暂停 | 不收费 |
| 24 小时内带同一个 Idempotency-Key 重发 | 直接返回保存的结果，不扣费 |

请求到了平台的调用，返回为空、查不到或出错也照常计费，收 $0.01；参数错误这类还没请求平台就被拦下的不扣费。

价格取自价目表版本 01188d61f8b07a6c。 [这个平台的全部价格](https://okdata.online/zh/pricing/google/)

- 新账号送 $0.20 试用额度，不用绑卡：够调这个接口 20 次。
- 查 1,000 次共 $10.00。

## 各视图返回的字段

“视图”一列是字段最早出现的 `view`：`compact` 只返回 compact 字段，`standard` 再加上 standard 字段，`full` 返回全部。默认是 `standard`。

- `compact`：`query`, `page`, `total_results`, `organic`, `ads`, `related_questions`, `related_searches`, `knowledge_panel`
- `standard`：`ai_overview`
- `full`：`ext`

## 这个接口的常见报错

| 状态码 | 代码 | 含义 | 是否扣费 | 能否重试 |
|---|---|---|---|---|
| 400 | `invalid_params` | 参数缺失、类型或取值不对，或者请求方法不对。problems 列出每一处问题，param 是第一个出错的参数。 | 否 | 修正后重试 |
| 401 | `unauthorized` | Key 缺失、格式不对、已撤销、已停用或已过期（知道原因时 reason 会写明）。 | 否 | 不要重试 |
| 402 | `insufficient_balance` | 余额（available）不够这次调用的最高费用（required）。 | 否 | 修正后重试 |
| 404 | `not_found` | 内容、账号或页面不存在或不公开。这次查询请求到了平台、且产生了费用，或者接口的 charge_when_not_found 大于 0 时，这个结果会计费：返回体里 charged 为 true，并给出 amount。 | 请求到了平台就扣一次 | 不要重试 |
| 429 | `rate_limited` | 账号这一分钟请求太多（reason: rate），或同时进行的调用太多（reason: concurrency）。 | 否 | 可以重试 |
| 500 | `settlement_unknown` | 数据已返回，但没能确认是否扣费。 | 查询后才知道 | 用同一个 Idempotency-Key 重试 |
| 502 | `fetch_failed` | 我们这边自动重试后，这次请求仍然失败了。如果请求到了平台、且这次请求产生了费用，就按接口价格计一次费（charged 为 true，并给出 amount）；否则不计费。 | 请求到了平台就扣一次 | 可以重试 |
| 503 | `capability_paused` | 这个接口暂时停用了，这次没有执行。 | 否 | 可以重试 |
| 504 | `timeout` | 数据没有及时返回。如果请求到了平台、且这次请求产生了费用，就按接口价格计一次费（charged 为 true，并给出 amount）；否则预扣退回。 | 请求到了平台就扣一次 | 可以重试 |

[全部错误码](https://okdata.online/zh/docs/errors/)

## 在你的 AI 里用

> 先读 https://okdata.online/zh/apis/google/search.md，再用 okdata 帮我调这个接口，key 在环境变量 OKDATA_API_KEY 里。用「Google 网页搜索」查一下，总结返回的结果。
