# 加载页面、弹窗或横幅内容

Operation / SDK: `resolveContent` · `resolve_content` · `ResolveContent`

按资源或固定版本读取独立 Page、Popup、Banner；宿主显式挂载并处理动作。

更新于 2026-11-05

[网页版本](https://www.longplayai.com/zh-hans/docs/api/resolve-content)

<a id="request"></a>

## 请求

- **凭据**: Server Key（传 `customerId`）或 Customer Token，权限 `content:read`。
- **SDK**: JavaScript `createLongplayServer().resolveContent` · JavaScript `createLongplay().resolveContent` · Python `resolve_content` · Go `ResolveContent`
- **成功状态**: HTTP 200

响应为示例数据。

**cURL: request.sh**

```bash
curl -X POST "$LONGPLAY_API_URL/api/v1/content/resolve" \
  -H "Authorization: Bearer $LONGPLAY_SERVER_KEY" \
  -H "X-Indiana-Protocol: 0.10" \
  -H "Content-Type: application/json" \
  -d '{
  "kind": "page",
  "selector": {
    "type": "resource",
    "id": "ddff7ca6-bfe7-445e-81a6-ca13bbf64a41"
  },
  "customerId": "8b258f8b-4228-40fa-8d24-5b16428e686d"
}'
```

**TypeScript: resolveContent.ts**

```ts
import { createLongplayServer } from "@tinkerlandai/longplay-sdk/server";

const longplay = createLongplayServer({
  baseUrl: process.env.LONGPLAY_API_URL!,
  apiKey: process.env.LONGPLAY_SERVER_KEY!,
  scope: { projectId: process.env.LONGPLAY_PROJECT_ID!, environment: "sandbox" },
});

export async function resolveContent() {
  return longplay.resolveContent({
    kind: "page",
    selector: {
      type: "resource",
      id: "ddff7ca6-bfe7-445e-81a6-ca13bbf64a41",
    },
    customerId: "8b258f8b-4228-40fa-8d24-5b16428e686d",
  });
}
```

**请求体: request.json**

```json
{
  "kind": "page",
  "selector": {
    "type": "resource",
    "id": "ddff7ca6-bfe7-445e-81a6-ca13bbf64a41"
  },
  "customerId": "8b258f8b-4228-40fa-8d24-5b16428e686d"
}
```

**响应示例: response.json**

```json
{
  "requestId": "44f5fcb8-6ed8-41b8-818f-7571941c5fd5",
  "scope": {
    "projectId": "df5426d6-b335-403c-8f3e-b0f73d2e3511",
    "environment": "sandbox"
  },
  "content": {
    "id": "8f927788-da75-46cc-8159-0491ab40c155",
    "kind": "page",
    "resourceId": "79322b17-a312-485e-8033-b532cdc16fe9",
    "projectId": "7ef5bbb4-a4fc-4e78-83f3-81854bb3b42d",
    "environmentId": "c109bd50-5064-4390-8761-1589f2515d2d",
    "version": 1,
    "sourceRevision": 0,
    "document": {
      "kind": "page",
      "schemaVersion": 1,
      "name": "Welcome",
      "screen": {
        "kind": "screen",
        "schemaVersion": 4,
        "theme": {
          "primary": "#2C3C96",
          "background": "#FFFFFF",
          "text": "#1B1D24",
          "radius": "md",
          "font": "system"
        },
        "name": "Welcome",
        "surface": "page",
        "presentation": {
          "type": "fullscreen"
        },
        "pages": [
          {
            "id": "main",
            "name": "Main page",
            "root": {
              "type": "stack",
              "id": "root",
              "direction": "vertical",
              "align": "stretch",
              "justify": "start",
              "name": "Canvas",
              "style": {
                "gap": 16,
                "padding": {
                  "top": 24,
                  "right": 24,
                  "bottom": 24,
                  "left": 24
                }
              },
              "children": []
            }
          }
        ],
        "strings": {
          "defaultLocale": "en",
          "locales": {
            "en": {}
          }
        },
        "actions": []
      },
      "contract": {
        "inputs": {},
        "outputs": {}
      }
    },
    "createdAt": "2026-10-03T12:00:00.000Z"
  }
}
```

<a id="parameters"></a>

## 请求体参数

**application/json**

- `kind` (enum, required): 类型，取值见允许值。 Values: `"page"`, `"popup"`, `"banner"`.
- `selector` (object | object, required): 选择 Offering 或 Paywall 的条件。
- `selector.type` ("resource" | "version", required): 选择方式。Offering：`current`（环境中设为当前的 Offering）、`id` 和 `lookup_key` 解析为该 Offering 已发布的 Version，`version` 固定到指定的 Offering Version；Paywall：`paywall` 解析为其已发布的 Version，`version` 固定到指定的 Paywall Version；Page、Popup、Banner：`resource` 解析资源当前发布的 Version，`version` 固定到已发布 Version。
- `selector.id` (uuid | uuid, required): Offering 选择器中为要解析的 Offering UUID。Page、Popup、Banner 中为资源或已发布 Version 的 UUID，由 selector.type 决定；已归档或未发布的资源返回未找到。
- `customerId` (string, optional): Customer 的 UUID。用 Server Key 调用时指定 Customer；Customer Token 调用时省略。 minLength: 1

<a id="response"></a>

## 响应字段

成功响应都包含 `requestId`（本次请求 ID，排查时提供）和 `scope`（App 与环境）。

**HTTP 200 · application/json**

- `requestId` (uuid, required): 服务端为这次 HTTP 请求生成的 UUID，排查时提供；它不是你的业务 requestId。
- `scope` (object, required): 响应实际所属的 App 和环境。Header 只能核对，不能切换 Key 范围。
- `scope.projectId` (string, required): 凭据绑定的 App ID。 minLength: 1
- `scope.environment` (enum, required): 独立数据范围：sandbox 或 live。 Values: `"sandbox"`, `"live"`.
- `content` (object, required): 固定版本的独立 Page、Popup 或 Banner。
- `content.id` (uuid, required): 返回内容版本的 UUID。
- `content.kind` (enum, required): 类型，取值见允许值。 Values: `"page"`, `"popup"`, `"banner"`.
- `content.resourceId` (uuid, required): 内容所属的独立资源 UUID。
- `content.projectId` (uuid, required): 凭据绑定的 App ID。
- `content.environmentId` (uuid, required): 环境的 ID。
- `content.version` (integer, required): 版本号。 max: 9007199254740991
- `content.sourceRevision` (integer, required): 发布该版本时的资源草稿修订号。 min: 0 · max: 9007199254740991
- `content.document` (object, required): 已发布的 schemaVersion 3 设计。缓存命中时可为 null；直接 HTTP 调用方须用匹配缓存还原。
- `content.document.kind` (enum, required): 类型，取值见允许值。 Values: `"page"`, `"popup"`, `"banner"`.
- `content.document.schemaVersion` (1, required): 数据格式版本。
- `content.document.name` (string, required): 展示名称，不作为唯一标识。 minLength: 1 · maxLength: 80
- `content.document.screen` (object, required): 由 SDK 渲染的屏幕文档。
- `content.document.screen.kind` ("screen", required): 类型，取值见允许值。
- `content.document.screen.schemaVersion` (4, required): 数据格式版本。
- `content.document.screen.name` (string, required): 展示名称，不作为唯一标识。 minLength: 1 · maxLength: 80
- `content.document.screen.surface` (enum, required): 屏幕所属的 Page、Popup 或 Banner 类型，须与内容类型一致。 Values: `"popup"`, `"paywall"`, `"onboarding"`, `"page"`, `"banner"`.
- `content.document.screen.initialPageId` (string, optional): 屏幕初次显示的内部页面 ID。 pattern: ^[a-zA-Z][a-zA-Z0-9_-]{0,63}$
- `content.document.screen.presentation` (object | object | object | object, required): 展示配置。
- `content.document.screen.theme` (object, required): 屏幕的颜色、圆角和字体主题。
- `content.document.screen.pages` (array, required): 该屏幕内的页面和组件树。 minItems: 1 · maxItems: 10
- `content.document.screen.strings` (object, required): 默认语言、已提供语言及其文案表。
- `content.document.screen.actions` (array, required): 屏幕中已声明的交互动作。 maxItems: 40
- `content.document.contract` (object, required): 独立内容对宿主声明的输入和输出类型。
- `content.document.contract.inputs` (object, required): 宿主可提供的变量、值类型及是否必填。
- `content.document.contract.outputs` (object, required): 该内容可向宿主输出的事件值类型。
- `content.createdAt` (date-time, required): 记录创建时的 ISO 8601 UTC 时间。

<a id="errors"></a>

## 错误

失败时返回错误对象，按 `error.code` 与 `error.recovery` 处理。下表是这个接口的凭据、作用域和幂等字段决定的错误；视请求内容还可能返回 `NOT_FOUND`（引用的资源不存在）、`NOT_CONFIGURED`（所需的集成未连接）或 `PAYLOAD_TOO_LARGE`。有些拒绝（如余额不足）不是错误，而是成功响应里的 `reason`。

**可能的错误**

| code | HTTP | 何时 | recovery |
| --- | --- | --- | --- |
| `INVALID_REQUEST` | 400 | 请求不符合本页的参数。缺少或无法解析协议头时分别返回 `UNSUPPORTED_PROTOCOL_VERSION` 或 `INVALID_PROTOCOL_VERSION`。 | `fix_request` |
| `UNAUTHENTICATED` | 401 | 凭据缺失、无效、过期或已撤销。 | `authenticate` |
| `FORBIDDEN` | 403 | 凭据没有 `content:read` 权限。 | `check_permissions` |
| `SCOPE_MISMATCH` | 403 | `X-Indiana-Project` 或 `X-Indiana-Environment` 与凭据所属的 App 和环境不一致。 | `check_scope` |
| `RATE_LIMITED` | 429 | 请求过多；按 `Retry-After` 等待后用同一请求重试。 | `retry_same_request` |
| `SERVICE_UNAVAILABLE` | 503 | 服务暂时不可用；用同一请求重试。 | `retry_same_request` |
| `INTERNAL_ERROR` | 500 | 结果未知；稍后重试。 | `recover_operation` |

- [错误码与恢复](https://www.longplayai.com/zh-hans/docs/api/errors.md)
- [请求约定](https://www.longplayai.com/zh-hans/docs/api.md)
- [全部接口](https://www.longplayai.com/zh-hans/docs/api/operations.md#integration)
