接口URL
https://api.polyv.net/v2/traffic/{userid}/video/{vid}
接口说明
(接口调用有频率限制,详细请查看)
- 查询给定的日期区间内视频每天消耗的流量
- 自2018年7月10日起,才可以统计到单个视频的移动端流量数据,在此之前没有移动端流量数据
- 流量消耗的计算依赖于CDN日志,为了保证数据完整性,流量数据需要间隔一个自然日才会生成。例如1号产生的流量消耗,会在2号晚上汇总计算,在3号才可查询到流量数据。
返回结果支持格式
JSON
请求方式
GET
请求参数
参数名 | 必选 | 类型及范围 | 说明 |
---|---|---|---|
userid | true | string | 用户id,路径参数 |
vid | true | string | 视频vid,路径参数 |
ptime | true | string | 当前13位毫秒级时间戳,3分钟内有效 |
sign | true | string | 签名,40位大写的sha1值 |
dr | false | string | 时间段,具体值为以下几个:today(今天),yesterday(昨天),this_week(本周),last_week(上周),7days(最近7天),this_month(本月),last_month(上个月),this_year(今年),last_year(去年),默认值为7days |
start | false | string | 开始日期,格式为yyyy-MM-dd |
end | false | string | 结束日期,格式为yyyy-MM-dd |
返回结果
{
"code": 200,
"status": "success",
"message": "success",
"data": [
{
"currentDay": "2018-07-14",
"pcFlowSize": 0,
"mobileFlowSize": 0,
"totalFlowSize": 0
},
{
"currentDay": "2018-07-15",
"pcFlowSize": 0,
"mobileFlowSize": 0,
"totalFlowSize": 0
},
{
"currentDay": "2018-07-16",
"pcFlowSize": 0,
"mobileFlowSize": 0,
"totalFlowSize": 0
},
{
"currentDay": "2018-07-17",
"pcFlowSize": 0,
"mobileFlowSize": 0,
"totalFlowSize": 0
},
{
"currentDay": "2018-07-18",
"pcFlowSize": 0,
"mobileFlowSize": 0,
"totalFlowSize": 0
},
{
"currentDay": "2018-07-19",
"pcFlowSize": 0,
"mobileFlowSize": 0,
"totalFlowSize": 0
},
{
"currentDay": "2018-07-20",
"pcFlowSize": 0,
"mobileFlowSize": 0,
"totalFlowSize": 0
}
]
}
失败返回json(不带jsonp)
{
"code": 400,
"status": "error",
"message": "ptime is too old.",
"data": ""
}
字段描述
字段名称 | 描述 |
---|---|
currentDay | 日期 |
pcFlowSize | PC端消耗流量,单位字节 |
mobileFlowSize | 移动端消耗流量,单位字节 |
totalFlowSize | 总流量消耗,单位字节 |
响应说明
错误代码 | message | 说明 |
---|---|---|
400 | sign can not be empty. | 加密串为空 |
400 | vid invalid. | 视频id错误 |
400 | ptime is too old. | 时间戳过期 |
400 | ptime is illegal. | 时间戳参数格式不对或者超过当前时间3分钟 |
400 | Could not find user by userid. | userid不存在 |
400 | the sign is not right. | 加密串不正确 |
401 | start and end illegal. | start日期大于end日期 |
500 | query failed. | 后台程序抛异常 |
200 | success | 提交成功 |
PHP请求示例
<?php
header("Content-type: text/html; charset=utf-8");
$userid="用户id";
$dr="7days";
$ptime=time()*1000;//13位
$secretkey="填写secretkey";
$str="dr=".$dr."&ptime=".$ptime.$secretkey;
$vid="b0f704132434cfe3fe8366c59f3875c0_b";
$hash=strtoupper(sha1($str));
$url="https://api.polyv.net/v2/traffic/$userid/video/$vid?ptime=$ptime&sign=$hash&dr=$dr";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
//打印获得的数据
print_r($output);
?>
签名规则:
将非空的请求参数按照参数名字典顺序排列,连接参数名与参数值,并在尾部加上secretkey,生成40位大写SHA1值,作为sign。 以下是示例过程:
1、请求参数为
ptime = "1492591990000"
vid = "382839019131be68715e9455f8d0971a_3"
format = "json"
2、将请求参数按照参数名字典顺序排列
format = "json"
ptime = "1492591990000"
vid = "382839019131be68715e9455f8d0971a_3"
3、连接字符串
连接参数名与参数值,并在尾部加上secretkey(secretkey的值为tIQp4ATe9Z),如下:
format=json&ptime=1492591990000&vid=382839019131be68715e9455f8d0971a_3tIQp4ATe9Z
4、生成签名sign
50BF9B165630A8047EB1D17D95A469CC51FF754E