# UDP API

> Reference for the Unity Distribution Portal API, a service that shut down in February 2025.

| **重要提示**                                                                                                                                                                                                                                                                                                 |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Unity Distribution Portal (UDP) 将于 2025 年 2 月 17 日关闭。自该日起，Unity Distribution Portal (UDP) 网页控制台及相关服务将永久停用。要下载密钥库以及如何将游戏直接重新发布到应用商店的说明，请访问 [UDP 概述](https://api-udp.unity.com/overview)页面。如果您对帐户有任何疑问，请向 [Unity 客户支持](https://support.unity.com/hc/en-us/requests/new?ticket_form_id=360000323692)部门提交工单。 |

UDP API 允许您将二进制文件上传到 UDP 控制台。这让您可以使用 CI 系统来构建您的应用并将输出直接推送到 UDP。请参阅[在 UDP 控制台上管理和发布游戏](/engine/6000.0/manual/unity-services/udp/managing-and-publishing.md#api-upload)。

支持以下文件类型：

* APK
* OBB
* AAB

## API 结构

API 结构如下所示：\[[https://distribute.dashboard.unity.com/developer/api/upload/:orgId/:clientId?token=xxxxxx](https://distribute.dashboard.unity.com/developer/api/upload/:orgId/:clientId?token=xxxxxx)[\&obbType=xxxx](https://distribute.dashboard.unity.com/developer/api/upload/:orgId/:clientId?token=xxxxxx%5B\&obbType=xxxx)]

下表描述了 API 的参数。

| 参数         | 描述                                                               |
| ---------- | ---------------------------------------------------------------- |
| `orgId`    | 要为其上传二进制文件的游戏的组织 ID。                                             |
| `clientId` | 要为其上传二进制文件的游戏的客户端 ID。                                            |
| `token`    | 在 UDP 控制台中生成的授权令牌，位于“开发者 API”页面上。                                |
| `obbType`  | 要上传的 OBB 文件类型。以下值有效：- `mainObb`- `patchObb`上传 OBB 文件时，只需指定此查询参数。 |

## 表单键

你可以在用 POST 方法将构建版本上传到 UDP 时，使用表单键来指定值。这些值对应于游戏信息 (Game Information) 选项卡的二进制文件 (Binary) 部分。

下表描述了表单键。

| 表单键                | 描述                                                | 必需/可选 |
| ------------------ | ------------------------------------------------- | ----- |
| `uploadFile`       | 指定要上传的文件的路径。                                      | 必需    |
| `whatsNew`         | 在 UDP 控制台中设置**新增功能**字段的值。                         | 可选    |
| `useGoogleService` | 在 UDP 控制台中设置\*\*您的游戏是否使用 Google Play 服务？\*\*字段的值。 | 可选    |

如果您不指定可选键，UDP 将使用您游戏的最新版本的值。

## 常见错误信息和错误代码

### 无效的身份验证令牌

如果您提供无效的身份验证令牌，您将收到状态代码为 401 的错误消息。

```
{"errorCode":"NotAuthenticated","message":"not authenticated error","target":"","details":null}
```

### 无效的组织 ID

如果您提供无效的组织 ID 或无效的客户端 ID，您将收到状态代码为 400 的错误消息。

```
{"errorCode":"InvalidParameter","message":"The given parameter is missing or invalid","target":"Invalid OrgId or ClientId","details":null}
```

### 无效的文件类型

如果您提供无效的文件类型，您将收到状态代码为 400 的错误消息。

```
{"errorCode":"InvalidParameter","message":"The given parameter is missing or invalid: please provide the right binary file(APK, AAB or OBB)","target":"file type","details":null}
```

### 无效的 OBB 类型

如果您提供无效的 OBB 类型，您将收到状态代码为 400 的错误消息。

```
{"errorCode":"InvalidParameter","message":"The given parameter is missing or invalid","target":"obbType","details":null}
```

### 无效的内容类型

如果您提供无效的内容类型，您将收到状态代码为 400 的错误消息。

```
{"errorCode":"InvalidParameter","message":"The given parameter is missing or invalid","target":"content type","details":null}
```
