文档

​
​

Development

User Acquisition

Monetization

工业

Cloud Code

Open Unity Dashboard

Cloud Code

LiveOps
​
​
Cloud Code
  • Overview
  • Get started
  • Server authority
  • Cloud Code C# modules
  • Cloud Code JavaScript scripts
    • Overview
    • Get started
    • Concepts
    • Tutorials
      • Run scripts
        • Unity Runtime
        • REST API
      • Write scripts
      • Interact with cross-player data
      • Integrate with CI/CD
      • Use Access Control
      • Test run a script
      • Integrate with other Unity Services
      • Integrate with external services
      • Use Cases
    • Reference
  • Logging
  • Use-case samples
  • Privacy and consent
  1. Cloud Code
  2. 运行脚本

调用 Cloud Code API

Invoke scripts by making HTTP requests to the Cloud Code REST API.
阅读时间2 分钟
最后更新于 9 个月前

调用 Cloud Code API 来运行脚本。请参阅 Cloud Code API 文档了解更多信息。

身份验证

请参阅身份验证,使用服务帐户或无状态令牌以玩家或受信任客户端的身份进行身份验证。请在请求标头中使用收到的令牌作为 HTTP 身份验证的持有者令牌:
Authorization: Bearer <BEARER_TOKEN>

运行脚本请求

通过向以下地址发送 POST 请求来调用 Cloud Code API:
https://cloud-code.services.api.unity.com/v1/projects/<PROJECT_ID>/scripts/<SCRIPT_NAME>
定义路径参数:
  • projectId
    - 项目的 ID。
  • scriptName
    - 脚本的名称。
一个简单的 cURL 命令如下所示:
curl --request POST 'https://cloud-code.services.api.unity.com/v1/projects/<PROJECT_ID>/scripts/<SCRIPT_NAME>' \--header 'Content-Type: application/json' \--header 'Authorization: Bearer <BEARER_TOKEN>'

请求有效负载

您可以在脚本中定义参数。这些参数会传入到请求正文中。如果脚本没有参数,则可以传入空的
params
对象。
{ "params": { "numericParam": 123, "stringParam": "abcdef", "booleanParam": true, "jsonParam": { "key": "value" } }}
一个完整的 cURL 命令如下所示:
curl --request POST 'https://cloud-code.services.api.unity.com/v1/projects/<PROJECT_ID>/scripts/<SCRIPT_NAME>' \--header 'Content-Type: application/json' \--header 'Authorization: Bearer <BEARER_TOKEN>' \--data-raw '{"params": { "numericParam": 123, "stringParam": "abcdef", "booleanParam": true, "jsonParam": { "key": "value" }}}'

示例输出

以下是返回
playerInfo
对象的脚本的示例输出。
{ "output": { "playerInfo": { "playerID": "TestUser", "userName": "TestUserName", "displayName": "Name", "email": "test@test.com", "country": null, "deviceType": null, "platform": "IOS", "dateCreated": "string" } }}

Copyright © 2026 Unity Technologies
法律信息隐私政策CookiesDocumentation Terms of Use请勿出售或分享我的个人信息您的隐私选择(Cookie 设置)

“Unity”、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属公司在美国和其他地方的商标或注册商标(此处查看更多信息)。其他名称或品牌是其各自所有者的商标。

为方便起见,一些页面是机器翻译的,可能包含不准确的内容。如有信息不一致的情况,以英文版本为准。

  • 在本页上
    • 身份验证

    • 运行脚本请求

    • 请求有效负载

    • 示例输出


报告此页面的问题