本文介绍Python SDK使用说明。请您按照以下步骤操作。
Python 2.7+
1.安装阿里云核心SDK
sudo pip install aliyun-python-sdk-core
sudo pip install aliyun-python-sdk-live
sudo pip install aliyun-python-sdk-core --upgrade
sudo pip install aliyun-python-sdk-live --upgrade
sudo pip uninstall aliyun-python-sdk-coresudo pip uninstall aliyun-python-sdk-live
以 DescribeLiveStreamsFrameRateAndBitRateData接口为例。
以下是SDK中的DescribeLiveStreamsFrameRateAndBitRateDataRequest.py
# Licensed to the Apache Software Foundation (ASF) under one# or more contributor license agreements. See the NOTICE file# distributed with this work for additional information# regarding copyright ownership. The ASF licenses this file# to you under the Apache License, Version 2.0 (the# "License"); you may not use this file except in compliance# with the License. You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0#### Unless required by applicable law or agreed to in writing,# software distributed under the License is distributed on an# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY# KIND, either express or implied. See the License for the# specific language governing permissions and limitations# under the License.from aliyunsdkcore.request import RpcRequestclass DescribeLiveStreamsFrameRateAndBitRateDataRequest(RpcRequest):def __init__(self):RpcRequest.__init__(self, 'live', '2016-11-01', 'DescribeLiveStreamsFrameRateAndBitRateData','live')def get_SecurityToken(self):return self.get_query_params().get('SecurityToken')def set_SecurityToken(self,SecurityToken):self.add_query_param('SecurityToken',SecurityToken)def get_OwnerId(self):return self.get_query_params().get('OwnerId')def set_OwnerId(self,OwnerId):self.add_query_param('OwnerId',OwnerId)def get_DomainName(self):return self.get_query_params().get('DomainName')def set_DomainName(self,DomainName):self.add_query_param('DomainName',DomainName)def get_AppName(self):return self.get_query_params().get('AppName')def set_AppName(self,AppName):self.add_query_param('AppName',AppName)def get_StreamName(self):return self.get_query_params().get('StreamName')def set_StreamName(self,StreamName):self.add_query_param('StreamName',StreamName)def get_StartTime(self):return self.get_query_params().get('StartTime')def set_StartTime(self,StartTime):self.add_query_param('StartTime',StartTime)def get_EndTime(self):return self.get_query_params().get('EndTime')def set_EndTime(self,EndTime):self.add_query_param('EndTime',EndTime)
该文件中对于DescribeLiveStreamsFrameRateAndBitRateDataRequest这个类,有若干组一一对应的get_X和set_X方法,分别用于设定该 API 请求的参数,具体每一个请求参数对应的意义,您可以在阿里云官网的直播 API 文档中找到。
以v20161101版本为例。
以调用DescribeLiveStreamsFrameRateAndBitRateDataRequest接口为例。
# 引入aliyunsdkcore包from aliyunsdkcore import client# 引入aliyunsdklie包from aliyunsdklive.request.v20161101 import DescribeLiveStreamsFrameRateAndBitRateDataRequest# 初始化client# AK和Secrect需要自己提供(可以在阿里云控制台中找到)# 以访问cn-hangzhou region为例clt = client.AcsClient(AK, Secret, 'cn-hangzhou')# 构造需发起的API请求调用request = DescribeLiveStreamsFrameRateAndBitRateDataRequest.DescribeLiveStreamsFrameRateAndBitRateDataRequest()request.set_DomainName('qt1.alivecdn.com')request.set_AppName('caster')request.set_StreamName('cc8d5e157f5d4146afd091e246efd1f6')# 发起请求result = clt.do_action_with_exception(request)# 请求结果# result为请求结果的ResponseBody字符串print result# 如果您需要进一步对result进行处理,可以根据每个接口的返回格式,进行格式化处理并进一步分析或使用# 对于DescribeLiveStreamsFrameRateAndBitRateDataRequest来说,它返回一个json格式的数据,我们可以用json包来处理这些responseimport jsonx = json.loads(result)print x['RequestId']print x['FrameRateAndBitRateInfos']