示例1:创建频道
本节通过调用一系列媒体直播的API来创建频道。
涉及API
当您使用Token认证方式完成认证鉴权时,需要获取用户Token并在调用接口时增加“X-Auth-Token”到业务接口请求消息头中。
操作步骤
- 获取用户Token,用于调用媒体直播接口时进行认证鉴权。
详细信息请参见构造请求。以“华北-北京四”为示例,若您需要调用其它区域的媒体直播接口,请替换成对应区域的IAM终端节点。
POST https://iam.cn-north-4.myhuaweicloud.com/v3/auth/tokens Content-Type: application/json { "auth": { "identity": { "methods": [ "password" ], "password": { "user": { "name": "username", "password": "password", "domain": { "name": "domainname" } } } }, "scope": { "project": { "name": "projectname" } } } }
如图1所示,红框中的信息为获取用户Token。 - 选择POST请求方法,并输入请求URI。
POST https://live.cn-north-4.myhuaweicloud.com/v1/{project_id}/ott/channels
“live.cn-north-4.myhuaweicloud.com”为媒体直播服务的终端节点,您可以在使用前必读中获取。调用IAM接口的区域需与调用媒体直播接口的区域一致,如调用“cn-north-4”区域的IAM接口获取用户Token,则该Token仅能用于调用“cn-north-4”区域媒体直播接口的鉴权。
- 在请求消息头中增加“X-Auth-Token”,值设置为1中获取的用户Token。
- 在请求消息体中传入如下所示的参数,具体参数说明可参考新建OTT频道接口。
{ "domain": "push.domain.com", "app_name": "ott", "id": "testChannel", "name": "testChannel", "input": { "input_protocol": "FLV_PULL", "sources": [ { "url": "http://push.domain.com/ott/testChannel/index.flv", "bitrate": 2048, "width": 2096, "height": 1024 } ] }, "record_settings": { "rollingbuffer_duration": 3600 }, "encoder_settings": [ { "template_id": "hd" } ], "endpoints": [ { "hls_package": [ { "url": "pull.domain.com/ott/testChannel/index.m3u8", "stream_selection": [ { "key": "bitrate=900000-1800000", "max_bandwidth": 1800000, "min_bandwidth": 900000 } ], "segment_duration_seconds": 4, "encryption": { "level": "content", "resource_id": "test", "system_ids": [ "FairPlay" ], "url": "http://IP:Port/tkm/v1/owner/Data", "speke_version": "1.0", "request_mode": "direct_http", "http_headers": [ { "key": "Authorization", "value": "Basic aHVhd2VpY********************XM1Qjd6" } ] } } ] } ], "state": "ON" }
请求响应成功后,无返回参数,状态码为201 Created。
若请求失败,返回如下所示的错误码及错误描述,状态码为400 Bad Request。
"result_code": "LIVE.100011001", "result_msg": "Request parameters is invalid"