配置 Postman 以进行媒体服务 v3 REST API 调用Configure Postman for Media Services v3 REST API calls

本文演示如何配置 Postman,以便可以使用它调用 Azure 媒体服务 (AMS) REST API。This article shows you how to configure Postman so it can be used to call Azure Media Services (AMS) REST APIs. 本文说明如何将环境和集合文件导入到 PostmanThe article shows how to import environment and collection files into Postman. 集合包含调用 Azure 媒体服务 (AMS) REST API 的 HTTP 请求的分组定义。The collection contains grouped definitions of HTTP requests that call Azure Media Services (AMS) REST APIs. 环境文件包含集合使用的变量。The environment file contains variables that are used by the collection.

开始开发之前,请查看使用媒体服务 v3 API 进行开发Before you start developing, review Developing with Media Services v3 APIs.

先决条件Prerequisites

  • 创建媒体服务帐户Create a Media Services account. 请务必记住资源组名称和媒体服务帐户名称。Make sure to remember the resource group name and the Media Services account name.

  • 获取访问 API 所需的信息Get information needed to access APIs

  • 安装 Postman REST 客户端,以便执行一些 AMS REST 教程中所示的 REST API。Install the Postman REST client to execute the REST APIs shown in some of the AMS REST tutorials.

    我们使用的是 Postman,但任何 REST 工具都适用。We are using Postman but any REST tool would be suitable. 其他适用的工具有:具有 REST 插件的 Visual Studio Code 或 Telerik Fiddler 。Other alternatives are: Visual Studio Code with the REST plugin or Telerik Fiddler.

重要

查看命名约定Review naming conventions.

下载 Postman 文件Download Postman files

克隆包含 Postman 集合和环境文件的 GitHub 存储库。Clone a GitHub repository that contains the Postman collection and environment files.

git clone https://github.com/Azure-Samples/media-services-v3-rest-postman.git

配置 PostmanConfigure Postman

配置环境Configure the environment

  1. 打开 Postman 应用。Open the Postman app.

  2. 在屏幕的右侧,选择“管理环境”选项。On the right of the screen, select the Manage environment option.

    管理环境

  3. 从“管理环境”对话框中,单击“导入”。From the Manage environment dialog, click Import.

  4. 浏览到克隆 https://github.com/Azure-Samples/media-services-v3-rest-postman.git 时下载的 Azure Media Service v3 Environment.postman_environment.json 文件。Browse to the Azure Media Service v3 Environment.postman_environment.json file that was downloaded when you cloned https://github.com/Azure-Samples/media-services-v3-rest-postman.git.

  5. Azure Media Service v3 Environment 环境已添加。The Azure Media Service v3 Environment environment is added.

    备注

    使用从上面的“访问媒体服务 API”部分获得的值更新访问权限变量。Update access variables with values you got from the Access the Media Services API section above.

  6. 双击所选的文件,并输入通过执行访问 API 步骤获得的值。Double-click on the selected file and enter values that you got by following the accessing API steps.

  7. 关闭对话框。Close the dialog.

  8. 从下拉列表中选择“Azure Media Service v3 Environment”环境。Select the Azure Media Service v3 Environment environment from the dropdown.

    选择环境

配置集合Configure the collection

  1. 单击“导入” 导入该集合文件。Click Import to import the collection file.

  2. 浏览到克隆 https://github.com/Azure-Samples/media-services-v3-rest-postman.git 时下载的 Media Services v3.postman_collection.json 文件Browse to the Media Services v3.postman_collection.json file that was downloaded when you cloned https://github.com/Azure-Samples/media-services-v3-rest-postman.git

  3. 选择 Media Services v3.postman_collection.json 文件。Choose the Media Services v3.postman_collection.json file.

    导入文件

获取 Azure AD 令牌Get Azure AD Token

在开始操作 AMS v3 资源之前,需要获取并设置 Azure AD 令牌,以用于服务主体身份验证。Before you start manipulating AMS v3 resources you need to get and set Azure AD Token for Service Principal Authentication.

  1. 在 Postman 应用的左窗口中,选择“步骤 1: 获取 AAD 身份验证令牌”。In the left window of the Postman app, select "Step 1: Get AAD Auth token".

  2. 然后,选择“获取适用于服务主体身份验证的 Azure AD 令牌”。Then, select "Get Azure AD Token for Service Principal Authentication".

  3. 按“发送”。Press Send.

    将会发送以下 POST 操作。The following POST operation is sent.

    https://login.partner.microsoftonline.cn/:tenantId/oauth2/token
    
  4. 响应会返回此令牌并将“AccessToken”环境变量设置为令牌值。The response comes back with the token and sets the "AccessToken" environment variable to the token value.

    获取 AAD 令牌

故障排除Troubleshooting

  • 如果应用程序失败并显示“HTTP 504:网关超时”,请确保没有将位置变量显式设置为媒体服务帐户的预期位置以外的值。If your application fails with "HTTP 504: Gateway Timeout", make sure that the location variable has not been explicitly set to a value other than the expected location of the Media Services account.
  • 如果收到“找不到帐户”错误,还请检查以确保将正文 JSON 消息中的 location 属性设置为媒体服务帐户所在的位置。If you get an "account not found" error, also check to make sure that the location property in the Body JSON message is set to the location that the Media Services account is in.

另请参阅See also

后续步骤Next steps