通過閱讀本文,您可以了解通過服務端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)
# 創建審核模板
censor_template_config = '{\"Scene\":[\"porn\",\"terrorism\"],\"Scope\":[\"title\",\"video\",\"audio\",\"cover\"]}'
create_custom_template_request = ice20201109_models.CreateCustomTemplateRequest(
name = 'sdk_sample_censor_template',
type = 7,
subtype = 1,
template_config = censor_template_config
)
create_custom_template_response = client.create_custom_template(create_custom_template_request)
print('[LOG]', json.dumps(create_custom_template_response.to_map()))
template_id = create_custom_template_response.body.custom_template.template_id
# 提交媒體審核作業
submit_censor_job_request = ice20201109_models.SubmitMediaCensorJobRequest(
input = ice20201109_models.SubmitMediaCensorJobRequestInput(
type = 'Media',
media = '1b1b9cd148034739af413150fded****'
),
output = "oss://test_bucket/censor/snapshot-{Count}.jpg",
template_id = template_id
)
submit_media_censor_job_response = client.submit_media_censor_job(submit_censor_job_request)
print('[LOG]', json.dumps(submit_media_censor_job_response.to_map()))
job_id = submit_media_censor_job_response.body.job_id
# 查詢媒體審核任務作業詳情
query_media_censor_job_request = ice20201109_models.QueryMediaCensorJobDetailRequest(
job_id = job_id
)
get_snapshot_job_response = client.query_media_censor_job_detail(query_media_censor_job_request)
print('[LOG]', json.dumps(get_snapshot_job_response.to_map()))
# 查詢媒體審核任務作業列表
query_media_censor_job_list_request = ice20201109_models.QueryMediaCensorJobListRequest(
job_ids=job_id
)
query_media_censor_job_list_response = client.query_media_censor_job_list(query_media_censor_job_list_request)
print('[LOG]', json.dumps(query_media_censor_job_list_response.to_map()))
if __name__ == '__main__':
Sample.main()
相關接口
文檔內容是否對您有幫助?