通过阅读本文,您可以了解通过服务端SDK调用OpenAPI管理智能媒体服务云剪辑工程的示例代码。
示例代码
您可以通过阿里云OpenAPI开发者门户在线调试。
import json
import os
import sys
from typing import List
from alibabacloud_ice20201109.client import Client as ICE20201109Client
# 引入阿里云IMS SDK
from alibabacloud_ice20201109 import models as ice20201109_models
# Credentials和云产品SDK都需引入Client,此处为创建别名
from alibabacloud_credentials.client import Client as CredClient
# 引入阿里云SDK核心包
from alibabacloud_tea_openapi.models import Config
#######需要的依赖#############
#pip install alibabacloud_credentials
#pip install alibabacloud_ice20201109==1.3.11
class Sample:
# 初始化客户端
@staticmethod
def create_client(region: str) -> ICE20201109Client:
# 使用默认凭证初始化Credentials Client
cred = CredClient()
config = Config(credential = cred)
# 配置云产品服务接入地址(endpoint)
config.endpoint = 'ice.' + region + '.aliyuncs.com'
# 使用Credentials Client初始化ECS Client
return ICE20201109Client(config)
# @staticmethod
# def create_client(
# access_key_id: str,
# access_key_secret: str,
# region: str,
# ) -> ICE20201109Client:
# 如需硬编码AccessKey ID和AccessKey Secret,代码如下,但强烈建议不要把AccessKey ID和AccessKey Secret保存到工程代码里,否则可能导致AccessKey泄露,威胁您账号下所有资源的安全
# config = open_api_models.Config(
# # 必填,您的 AccessKey ID,
# access_key_id = access_key_id,
# # 必填,您的 AccessKey Secret,
# access_key_secret = access_key_secret
# )
# # 访问的域名
# config.endpoint = 'ice.' + region + '.aliyuncs.com'
# return ICE20201109Client(config)
# 读取命令行参数
@staticmethod
def main() -> None:
region = 'cn-shanghai'
# 初始化客户端
client = Sample.create_client(region)
# 创建云剪辑工程
create_editing_project = ice20201109_models.CreateEditingProjectRequest()
create_editing_project.title = '测试工程名字'
create_editing_project.description = '测试工程描述'
create_editing_project.timeline = "{\"VideoTracks\":[{\"VideoTrackClips\":[{\"MediaId\":\"****81539d420bb04d8ac4f48f2c****\"},{\"MediaId\":\"****20b48fb04483915d4f2cd8ac****\"}]}]}"
create_editing_project.cover_url = 'http://xxxx/coverUrl.jpg'
create_editing_response = client.create_editing_project(create_editing_project)
print(create_editing_response)
print('request id:', create_editing_response.body.request_id)
print('project:', create_editing_response.body.project)
# 获取单个云剪辑工程
get_editing_project = ice20201109_models.GetEditingProjectRequest()
get_editing_project.project_id = '<your-project-id>'
get_editing_response = client.get_editing_project(get_editing_project)
print(get_editing_response)
print('request id:', get_editing_response.body.request_id)
print('project:', get_editing_response.body.project)
# 修改云剪辑工程
update_editing_project = ice20201109_models.UpdateEditingProjectRequest()
update_editing_project.project_id = '<your-project-id>'
update_editing_project.timeline = "{\"VideoTracks\":[{\"VideoTrackClips\":[{\"MediaId\":\"****81539d420bb04d8ac4f48f2c****\"},{\"MediaId\":\"****20b48fb04483915d4f2cd8ac****\"}]}]}"
update_editing_response = client.update_editing_project(request)
print(update_editing_response)
print('request id:', update_editing_response.body.request_id)
# 删除云剪辑工程
delete_editing_projects = ice20201109_models.DeleteEditingProjectsRequest()
delete_editing_projects.project_ids = '<your-project-id-1>, <your-project-id-2>'
delete_editing_response = client.delete_editing_projects(delete_editing_projects)
print(delete_editing_response)
print('request id:', delete_editing_response.body.request_id)
print('ignored list:', delete_editing_response.body.ignored_list)
# 搜索云剪辑工程
search_editing_project = ice20201109_models.SearchEditingProjectRequest()
search_editing_project.max_results = 10
search_editing_response = client.search_editing_project(search_editing_project)
print(search_editing_response)
print('request id:', search_editing_response.body.request_id)
print('project list:', search_editing_response.body.project_list)
print('next token', search_editing_response.body.next_token)
print('max results', search_editing_response.body.max_results)
print('total count', search_editing_response.body.total_count)
if __name__ == '__main__':
Sample.main()
相关接口
文档内容是否对您有帮助?