接口URL
https://api.polyv.net/v2/hourly/{userid}
接口说明
(接口调用有频率限制,详细请查看)
- 该接口用于查询视频播放时段统计数据
- 从播放行为产生到数据可查询的间隔时间为1~2小时,但是统计结果中流量消耗(PCFlowSize、mobileFlowSize字段)的计算依赖于CDN日志,为了保证数据完整性,流量数据需要间隔一个自然日才会生成。例如1号产生的流量消耗,会在2号晚上汇总计算,在3号才可查询到流量数据。
返回结果支持格式
JSON
请求方式
GET
请求参数
参数名 | 必选 | 类型及范围 | 说明 |
---|---|---|---|
userid | true | string | 用户id,路径参数 |
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": [
{
"currentHour": 0,
"formatPcPlayDuration": "00:00:00",
"pcPlayDuration": 0,
"pcFlowSize": 0,
"pcVideoView": 0,
"pcUniqueViewer": 0,
"formatMobilePlayDuration": "00:00:00",
"mobilePlayDuration": 0,
"mobileFlowSize": 0,
"mobileVideoView": 0,
"mobileUniqueViewer": 0
},
{
"currentHour": 1,
"formatPcPlayDuration": "00:00:00",
"pcPlayDuration": 0,
"pcFlowSize": 0,
"pcVideoView": 0,
"pcUniqueViewer": 0,
"formatMobilePlayDuration": "00:00:00",
"mobilePlayDuration": 0,
"mobileFlowSize": 0,
"mobileVideoView": 0,
"mobileUniqueViewer": 0
},
{
"currentHour": 2,
"formatPcPlayDuration": "00:00:00",
"pcPlayDuration": 0,
"pcFlowSize": 0,
"pcVideoView": 0,
"pcUniqueViewer": 0,
"formatMobilePlayDuration": "00:00:00",
"mobilePlayDuration": 0,
"mobileFlowSize": 0,
"mobileVideoView": 0,
"mobileUniqueViewer": 0
},
{
"currentHour": 3,
"formatPcPlayDuration": "00:00:00",
"pcPlayDuration": 0,
"pcFlowSize": 0,
"pcVideoView": 0,
"pcUniqueViewer": 0,
"formatMobilePlayDuration": "00:00:00",
"mobilePlayDuration": 0,
"mobileFlowSize": 0,
"mobileVideoView": 0,
"mobileUniqueViewer": 0
},
{
"currentHour": 4,
"formatPcPlayDuration": "00:00:00",
"pcPlayDuration": 0,
"pcFlowSize": 0,
"pcVideoView": 0,
"pcUniqueViewer": 0,
"formatMobilePlayDuration": "00:00:00",
"mobilePlayDuration": 0,
"mobileFlowSize": 0,
"mobileVideoView": 0,
"mobileUniqueViewer": 0
},
{
"currentHour": 5,
"formatPcPlayDuration": "00:00:00",
"pcPlayDuration": 0,
"pcFlowSize": 0,
"pcVideoView": 0,
"pcUniqueViewer": 0,
"formatMobilePlayDuration": "00:00:00",
"mobilePlayDuration": 0,
"mobileFlowSize": 0,
"mobileVideoView": 0,
"mobileUniqueViewer": 0
},
{
"currentHour": 6,
"formatPcPlayDuration": "00:00:00",
"pcPlayDuration": 0,
"pcFlowSize": 0,
"pcVideoView": 0,
"pcUniqueViewer": 0,
"formatMobilePlayDuration": "00:00:00",
"mobilePlayDuration": 0,
"mobileFlowSize": 0,
"mobileVideoView": 0,
"mobileUniqueViewer": 0
},
{
"currentHour": 7,
"formatPcPlayDuration": "00:00:00",
"pcPlayDuration": 0,
"pcFlowSize": 0,
"pcVideoView": 0,
"pcUniqueViewer": 0,
"formatMobilePlayDuration": "00:00:00",
"mobilePlayDuration": 0,
"mobileFlowSize": 0,
"mobileVideoView": 0,
"mobileUniqueViewer": 0
},
{
"currentHour": 8,
"formatPcPlayDuration": "00:00:00",
"pcPlayDuration": 0,
"pcFlowSize": 0,
"pcVideoView": 0,
"pcUniqueViewer": 0,
"formatMobilePlayDuration": "00:00:00",
"mobilePlayDuration": 0,
"mobileFlowSize": 0,
"mobileVideoView": 0,
"mobileUniqueViewer": 0
},
{
"currentHour": 9,
"formatPcPlayDuration": "00:12:11",
"pcPlayDuration": 731,
"pcFlowSize": 1503824,
"pcVideoView": 9,
"pcUniqueViewer": 5,
"formatMobilePlayDuration": "00:02:28",
"mobilePlayDuration": 148,
"mobileFlowSize": 0,
"mobileVideoView": 2,
"mobileUniqueViewer": 2
},
{
"currentHour": 10,
"formatPcPlayDuration": "00:00:25",
"pcPlayDuration": 25,
"pcFlowSize": 7048405,
"pcVideoView": 5,
"pcUniqueViewer": 5,
"formatMobilePlayDuration": "00:00:29",
"mobilePlayDuration": 29,
"mobileFlowSize": 0,
"mobileVideoView": 2,
"mobileUniqueViewer": 2
},
{
"currentHour": 11,
"formatPcPlayDuration": "00:02:08",
"pcPlayDuration": 128,
"pcFlowSize": 5549169,
"pcVideoView": 7,
"pcUniqueViewer": 6,
"formatMobilePlayDuration": "00:00:00",
"mobilePlayDuration": 0,
"mobileFlowSize": 0,
"mobileVideoView": 0,
"mobileUniqueViewer": 0
},
{
"currentHour": 12,
"formatPcPlayDuration": "00:00:00",
"pcPlayDuration": 0,
"pcFlowSize": 0,
"pcVideoView": 0,
"pcUniqueViewer": 0,
"formatMobilePlayDuration": "00:00:00",
"mobilePlayDuration": 0,
"mobileFlowSize": 0,
"mobileVideoView": 0,
"mobileUniqueViewer": 0
},
{
"currentHour": 13,
"formatPcPlayDuration": "00:00:14",
"pcPlayDuration": 14,
"pcFlowSize": 4640879,
"pcVideoView": 3,
"pcUniqueViewer": 2,
"formatMobilePlayDuration": "00:00:00",
"mobilePlayDuration": 0,
"mobileFlowSize": 0,
"mobileVideoView": 0,
"mobileUniqueViewer": 0
},
{
"currentHour": 14,
"formatPcPlayDuration": "00:02:53",
"pcPlayDuration": 173,
"pcFlowSize": 1633231,
"pcVideoView": 8,
"pcUniqueViewer": 4,
"formatMobilePlayDuration": "00:00:00",
"mobilePlayDuration": 0,
"mobileFlowSize": 0,
"mobileVideoView": 0,
"mobileUniqueViewer": 0
},
{
"currentHour": 15,
"formatPcPlayDuration": "00:01:24",
"pcPlayDuration": 84,
"pcFlowSize": 0,
"pcVideoView": 2,
"pcUniqueViewer": 2,
"formatMobilePlayDuration": "00:00:09",
"mobilePlayDuration": 9,
"mobileFlowSize": 0,
"mobileVideoView": 1,
"mobileUniqueViewer": 1
},
{
"currentHour": 16,
"formatPcPlayDuration": "00:00:34",
"pcPlayDuration": 34,
"pcFlowSize": 1461340,
"pcVideoView": 7,
"pcUniqueViewer": 2,
"formatMobilePlayDuration": "00:00:00",
"mobilePlayDuration": 0,
"mobileFlowSize": 0,
"mobileVideoView": 0,
"mobileUniqueViewer": 0
},
{
"currentHour": 17,
"formatPcPlayDuration": "00:02:12",
"pcPlayDuration": 132,
"pcFlowSize": 3809560,
"pcVideoView": 10,
"pcUniqueViewer": 4,
"formatMobilePlayDuration": "00:00:19",
"mobilePlayDuration": 19,
"mobileFlowSize": 0,
"mobileVideoView": 1,
"mobileUniqueViewer": 1
},
{
"currentHour": 18,
"formatPcPlayDuration": "00:06:17",
"pcPlayDuration": 377,
"pcFlowSize": 0,
"pcVideoView": 1,
"pcUniqueViewer": 1,
"formatMobilePlayDuration": "00:00:00",
"mobilePlayDuration": 0,
"mobileFlowSize": 0,
"mobileVideoView": 0,
"mobileUniqueViewer": 0
},
{
"currentHour": 19,
"formatPcPlayDuration": "00:00:00",
"pcPlayDuration": 0,
"pcFlowSize": 0,
"pcVideoView": 0,
"pcUniqueViewer": 0,
"formatMobilePlayDuration": "00:00:00",
"mobilePlayDuration": 0,
"mobileFlowSize": 0,
"mobileVideoView": 0,
"mobileUniqueViewer": 0
},
{
"currentHour": 20,
"formatPcPlayDuration": "00:00:00",
"pcPlayDuration": 0,
"pcFlowSize": 0,
"pcVideoView": 0,
"pcUniqueViewer": 0,
"formatMobilePlayDuration": "00:00:00",
"mobilePlayDuration": 0,
"mobileFlowSize": 0,
"mobileVideoView": 0,
"mobileUniqueViewer": 0
},
{
"currentHour": 21,
"formatPcPlayDuration": "00:00:00",
"pcPlayDuration": 0,
"pcFlowSize": 0,
"pcVideoView": 0,
"pcUniqueViewer": 0,
"formatMobilePlayDuration": "00:00:00",
"mobilePlayDuration": 0,
"mobileFlowSize": 0,
"mobileVideoView": 0,
"mobileUniqueViewer": 0
},
{
"currentHour": 22,
"formatPcPlayDuration": "00:00:00",
"pcPlayDuration": 0,
"pcFlowSize": 0,
"pcVideoView": 0,
"pcUniqueViewer": 0,
"formatMobilePlayDuration": "00:00:00",
"mobilePlayDuration": 0,
"mobileFlowSize": 0,
"mobileVideoView": 0,
"mobileUniqueViewer": 0
},
{
"currentHour": 23,
"formatPcPlayDuration": "00:00:00",
"pcPlayDuration": 0,
"pcFlowSize": 0,
"pcVideoView": 0,
"pcUniqueViewer": 0,
"formatMobilePlayDuration": "00:00:00",
"mobilePlayDuration": 0,
"mobileFlowSize": 0,
"mobileVideoView": 0,
"mobileUniqueViewer": 0
}
]
}
失败返回json(不带jsonp)
{
"code": 400,
"status": "error",
"message": "ptime is too old.",
"data": ""
}
字段描述
字段名称 | 描述 |
---|---|
currentHour | 时段 |
pcPlayDuration | pc播放时长,单位为秒 |
formatPcPlayDuration | pc播放时长,格式为00:00:00 |
pcFlowSize | pc消耗流量,单位为字节 |
pcVideoView | pc端播放量 |
pcUniqueViewer | pc端观众量 |
mobilePlayDuration | 移动端播放时长,单位为秒 |
formatMobilePlayDuration | 移动端播放时长,格式为00:00:00 |
mobileFlowSize | 移动端消耗流量,单位为字节 |
mobileVideoView | 移动端播放量 |
mobileUniqueViewer | 移动端观众量 |
响应说明
错误代码 | message | 说明 |
---|---|---|
400 | sign can not be empty. | 加密串为空 |
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="this_year";
$start="2018-01-01";
$end="2018-07-06";
$ptime=time()*1000;//13位
$secretkey="填写secretkey";
$str="end=".$end."&ptime=".$ptime."&start=".$start.$secretkey;
$hash=strtoupper(sha1($str));
$url="http://api.polyv.net/v2/hourly/$userid?ptime=$ptime&sign=$hash&start=$start&end=$end";
$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