---
title: 与外部服务集成
product: Cloud Code
version: 3.1.0
latest_version: 3.1.0
status: This page documents version 3.1.0. The latest version is 3.1.0.
canonical: https://docs.unity.com/zh-cn/cloud-code/3.1.0/scripts/how-to-guides/external-services-integration
latest_url: https://docs.unity.com/zh-cn/cloud-code/3.1.0/scripts/how-to-guides/external-services-integration.md
last_updated: 2026-11-20
generated_at: 2026-12-03T02:23:22.931Z
locale: zh-cn
---

# 与外部服务集成

> Call public internet endpoints and public APIs from your Cloud Code scripts.

借助 Cloud Code，您可以调用任何公共互联网终端，包括属于 UGS 的[公共 API](https://services.docs.unity.com/cloud-code/v1)。

以下示例演示了如何调用 [Cat Facts API](https://catfact.ninja/#/facts/getrandomfact) 以获取随机 cat fact。

###### JavaScript##javascript

```js
const axios = require("axios-0.21");

module.exports = async ({ params, context, logger }) => {
  let result;
  try {
    const catFactUrl = `https://catfact.ninja/fact`;
    result = await axios.get(catFactUrl);

    return result.data;
  } catch (err) {
    logger.error("Failed to call out to Cat Facts", {"error.message": err.message});
    throw err;
  }
};
```

如需了解更多信息，请查看如何[与其他 Unity 服务集成](./unity-services-integration.md)。
