> For the complete documentation index, see [llms.txt](https://docs.exoclick.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.exoclick.com/api/zh/guang-gao-tou-fang-api/ad-plac-request.md).

# 请求

广告位 API 可以从以下任一端调用 **客户端** 端或 **服务端** 端。

当使用 **客户端** 端实现时，浏览器可能会执行一次 **预检** 请求。如果你想避免这种情况，请在请求头中使用 `Content-Type: text/plain`。这将确保浏览器将该请求判定为“简单”请求，从而跳过预检请求。

另外，在调用该 API 的 **客户端** 端时， **实际上并不需要 IP** 因为在前端和 Javascript 中检测 IP 可能很困难。相反，我们的 API 会在发起请求时从连接中检测 IP。

当使用 **服务端** 端实现时，为确保正确定向， **应明确传递用户的正确 IP**。否则，广告将按服务器位置定向，这可能导致后续因 IP 不匹配而使展示失效。

无论使用客户端还是服务端，如果传入了 IP，将优先于我们检测到的 IP。

要向广告位 API 发起请求，你需要传入两个对象： **用户** 和 **广告位**。该请求通过 HTTP POST 以 JSON 格式发送。

## 用户

| 参数                  | 必填？ | 说明                                                                                                                            |
| ------------------- | --- | ----------------------------------------------------------------------------------------------------------------------------- |
| id                  | 否   | 用户 ID                                                                                                                         |
| ip                  | 推荐  | 用户的 IP 地址。                                                                                                                    |
| ua                  | 是   | User Agent：包含用户浏览器/应用以及设备/操作系统的字符串。                                                                                           |
| language            | 否   | 使用以下方式设置请求语言： [标准的两个字符 ISO 代码](https://www.andiamo.co.uk/resources/iso-language-codes/) 再加上一个可选的 2 字符地区代码。例如： `en-us` 表示美国英语。 |
| referer             | 否   | 将展示广告的网站地址。                                                                                                                   |
| el                  | 否   | 用户的 Base64 编码邮箱。                                                                                                              |
| screen\_resolution  | 否   | 用户所使用设备的屏幕分辨率                                                                                                                 |
| window\_orientation | 否   | 如果网站是移动端布局，则应为“portrait”；如果是桌面端布局，则应为“landscape”。                                                                             |
| gdpr                | 否   | 隐私提示扩展（对象）。                                                                                                                   |

### user.gdpr

| 参数      | 说明                                                        |
| ------- | --------------------------------------------------------- |
| gdpr    | 这应该是 **0** 如果调用方认为用户不受 GDPR 约束，则为 **1** 如果用户受 GDPR 约束，则为。 |
| consent | 这是 IAB 标准要求的同意字符串。                                        |

## 广告位

| 参数                | 必填？ | 说明                                                                                                                                                                                      |
| ----------------- | --- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| id                | 是   | 广告位 ID                                                                                                                                                                                  |
| sub               | 否   | 广告位的子 ID                                                                                                                                                                                |
| sub2              | 否   | 附加子 ID（可选）。参见 [使用附加子 ID](https://docs.exoclick.com/publishers/zh/wang-zhan-yu-ban-wei/additional-subids.md).                                                                            |
| sub3              | 否   | 附加子 ID（可选）。参见 [使用附加子 ID](https://docs.exoclick.com/publishers/zh/wang-zhan-yu-ban-wei/additional-subids.md).                                                                            |
| keywords          | 否   | 任何 [keywords](https://docs.exoclick.com/advertisers/zh/guang-gao-xi-lie/chuang-jian-guang-gao-xi-lie/create-campaign-step3.md#keywords) 与可能匹配某一特定广告类型的流量相关联的关键词。如果没有关键词，将使用网站的 URL 进行匹配 |
| block\_ad\_types  | 否   | 此请求要屏蔽的广告类型列表，以逗号分隔。                                                                                                                                                                    |
| custom\_targeting | 否   | 自定义广告位值（对象）                                                                                                                                                                             |

### zones.custom\_targeting

| 参数     | 说明                                                  |
| ------ | --------------------------------------------------- |
| ex\_av | 这应该是 **0** 如果未定义， **1** 如果已验证年龄，则为 **2** 如果未验证年龄，则为 |

## 示例

可以在一次请求中请求多个广告位。每个广告位都会有不同的 ID，正如下方示例所示。

```json
{
  "user": {
    "id": "abdef8u9",
    "ip": "10.42.0.1",
    "ua": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.63 Safari/537.36",
    "language": "en-US",
    "referer": "https://blabla.com",
    "gdpr": {
      "gdpr": 1,
      "consent": "CPAoZRHPArq3hBcADBENBJCgAAAAAAAAAAqIHKQAAOUgAAAA"
    }
  },
  "zones": [
    {
      "id": 4031007,
      "sub": 111,
      "keywords": "humour, general"
    },
    {
      "id": 4031015,
      "sub": 222
    },
    {
      "id": 4031019,
      "sub": 222
    }
  ]
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.exoclick.com/api/zh/guang-gao-tou-fang-api/ad-plac-request.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
