OpenAPI sample code
This topic provides a complete example of how to use an OpenAPI to search for media workflows.
View the OpenAPI document
Read the API overview. The API for searching media workflows is SearchMediaWorkflow - Search for a media workflow. Before you call this API, read its documentation to understand the required parameters and permissions.
Create a RAM user and grant permissions
Identity
You can use an Alibaba Cloud account, a Resource Access Management (RAM) user, or a RAM role to call this API. This example uses a RAM user.
Log on to the Resource Access Management (RAM) console. Create a RAM user that has programmatic access only and record the AccessKey information. For more information, see Create a RAM user.
Authorization
Go to the RAM Users page. In the Actions column of the target RAM user, click Add Permissions.
In the search box, enter the keyword
MTSand select the AliyunMTSFullAccess policy.NoteThe system policies for ApsaraVideo Media Processing are as follows:
AliyunMTSFullAccess: Grants permissions to manage ApsaraVideo Media Processing (MTS).
AliyunMTSPlayerAuth: Grants permissions to use the ApsaraVideo Media Processing (MTS) player.
For information about how to create a custom policy, see Authorization information.
Click OK to complete the authorization.
Credentials
An AccessKey is generated by default when you create a RAM user. You can use this AccessKey.
Alternatively, go to the details page of the RAM user. On the Credentials tab, click Create AccessKey to create a new AccessKey. For more information, see Create an AccessKey.
Call the OpenAPI
This topic uses Python as an example to demonstrate how to call the OpenAPI.
Prepare the Python environment
Download and install Python.
For the download link for Python 3, see Python 3.
Check the Python version.
For Linux and macOS
Open the terminal and run the
python --versioncommand.For Windows
In the installation path of Python, double-click python.exe.
Open the Command Prompt window.
Press the Win+R keyboard shortcut to open the Run dialog box. Enter python and click OK.
Configure environment variables
For information about how to configure environment variables, see Configure environment variables on Linux, macOS, and Windows.
Install dependencies
pip install alibabacloud_credentials
pip install alibabacloud_mts20140618==3.3.42
pip install alibabacloud_tea_consoleDownload the sample code
In the OpenAPI Portal, access the Test URL of the SearchMediaWorkflow - Search media workflow API.
Enter the media workflow state list and paging parameters, and then click Call API.
After the call is successful, click the SDK Sample tab, select Python, and then click Download Complete Project to download the SDK sample for Python.
Decompress the Python sample code package on your computer and go to the
alibabacloud_samplefolder.
Run the code
Run the following command.
python sample.pyThe following output is returned:
{
"headers": {
"date": "Mon, 04 Sep 2023 09:55:25 GMT",
"content-type": "application/json;charset=utf-8",
"content-length": "137",
"connection": "keep-alive",
"keep-alive": "timeout=25",
"access-control-allow-origin": "*",
"access-control-expose-headers": "*",
"x-acs-request-id": "C4849AF2-D00E-52D0-A959-E6558E*****",
"x-acs-trace-id": "bff538ce7eaca3faf8600b0140******",
"etag": "1o4iLdylGKZzvHXcAQ*****"
},
"statusCode": 200,
"body": {
"MediaWorkflowList": {
"MediaWorkflow": []
},
"PageNumber": 1,
"PageSize": 10,
"RequestId": "C4849AF2-D00E-52D0-A959-E6558******",
"TotalCount": 0
}
}