查询播放时长统计
更新时间:2025-01-14 16:15:31
接口描述
1、通过视频id和时间范围查询单个或全部视频的播放时长统计数据,播放后生成数据需间隔一到两小时
2、接口URL中的{userid}为点播账号userid,具体参考菜单【使用须知】->【获取密钥】
3、接口支持https协议
接口URL
http://api.polyv.net/v2/play-duration/{userid}
请求方式
GET
接口约束
1、接口同时支持HTTP 、HTTPS ,建议使用HTTPS 确保接口安全,接口调用有频率限制,详细请查看
2、请求参数中start(开始日期)与end(结束日期)需要同时传入,仅传一个参数不生效
3、同时传入dr(时间段)与start、end的情况下,仅start、end有效;都不传则dr为默认值7days
请求参数描述
| 参数名 | 必选 | 类型 | 说明 |
|---|---|---|---|
| ptime | true | Long | 当前时间的毫秒级时间戳,3分钟内有效 |
| sign | true | String | 签名,为40位大写的SHA1值,生成签名的secretkey密钥作为通信数据安全的关键信息,严禁保存在客户端直接使用,所有API都必须通过客户自己服务器中转调用POLYV服务器获取响应数据【详见签名生成规则】 |
| vid | false | String | 视频id,不传则查询用户所有视频的播放时长数据 |
| dr | false | String | 时间段,默认值为7days,最近7天 today:今天 yesterday:昨天 this_week:本周 last_week:上周 7days:最近7天 this_month:本月 last_month:上个月 this_year:今年 last_year:去年 |
| start | false | String | 开始日期,格式为yyyy-MM-dd,例如:2021-03-30 |
| end | false | String | 结束日期,格式为yyyy-MM-dd,例如:2021-04-01 |
示例
http://api.polyv.net/v2/play-duration/1b448be323?vid=1b448be323b8d9b9489dcd7e8e09f087_1&start=2021-03-30&sign=645AB5A43A556E6D6AF8A577C287266E0BC822D1&end=2021-04-01&ptime=1617767033059
响应参数描述
| 参数名 | 类型 | 说明 |
|---|---|---|
| code | Integer | 响应状态码,200为成功返回,非200为失败【详见全局错误说明】 |
| status | String | 响应状态文本信息 |
| message | String | 响应描述信息,当code为400或者500的时候,辅助描述错误原因 |
| data | Array | 响应成功返回视频播放时长统计数据,响应失败返回空【详见data字段说明】 |
data参数描述
| 字段 | 类型 | 说明 |
|---|---|---|
| currentDay | String | 数据生成日期,格式为:yyyy-MM-dd |
| pcPlayDuration | Integer | pc端播放时长,单位秒 |
| formatPcPlayDuration | String | 格式化的pc端播放时长,格式为:时:分:秒 |
| pcPlayDurationVideoAvg | Integer | pc端视频平均播放时长,单位秒 |
| formatPcPlayDurationVideoAvg | String | 格式化的pc端视频平均播放时长,格式为:时:分:秒 |
| pcPlayDurationPersonAvg | Integer | pc端人均播放时长,单位秒 |
| formatPcPlayDurationPersonAvg | String | 格式化的pc端人均播放时长,格式为:时:分:秒 |
| mobilePlayDuration | Integer | 移动端播放时长,单位秒 |
| formatMobilePlayDuration | String | 格式化的移动端播放时长,格式为:时:分:秒 |
| mobilePlayDurationVideoAvg | Integer | 移动端视频平均播放时长,单位秒 |
| formatMobilePlayDurationVideoAvg | String | 格式化的移动端视频平均播放时长,格式为:时:分:秒 |
| mobilePlayDurationPersonAvg | Integer | 移动端人均播放时长,单位秒 |
| formatMobilePlayDurationPersonAvg | String | 格式化的移动端人均播放时长,格式为:时:分:秒 |
返回错误代码列表
| 错误代码 | message | 说明 |
|---|---|---|
| 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日期 |
Java请求示例
快速接入基础代码请下载相关依赖源码, 点击下载源代码 ,下载后加入到自己的源码工程中即可。测试用例中的HttpUtil.java 和 VodSignUtil.java 都包含在下载文件中。
强烈建议您使用点播Java SDK完成API的功能对接,点播Java SDK 对API调用逻辑、异常处理、数据签名、HTTP请求线程池进行了统一封装和优化。
private static final Logger log = LoggerFactory.getLogger(VodStatisticsTest.class);
/**
* 查询播放时长统计
* @throws Exception
* @throws NoSuchAlgorithmException
*/
@Test
public void testGetPlayDuration() throws Exception, NoSuchAlgorithmException {
//公共参数,填写自己的实际参数
String secretKey = super.secretKey;
String userId = super.userId;
String ptime = String.valueOf(System.currentTimeMillis());
//业务参数
String url = String.format("http://api.polyv.net/v2/play-duration/%s", userId);
String vid = "1b448be323b8d9b9489dcd7e8e09f087_1";
String dr = "last_month";
String start = "2021-03-30";
String end = "2021-04-01";
Map<String, String> requestMap = new HashMap<>();
requestMap.put("ptime", ptime);
requestMap.put("vid", vid);
requestMap.put("start", start);
requestMap.put("end", end);
requestMap.put("sign", VodSignUtil.getSign(requestMap, secretKey));
String response = HttpUtil.get(url, requestMap);
log.debug("测试查询播放时长统计,{}", response);
//do somethings
}
响应示例
系统全局错误说明详见全局错误说明
成功示例
{
"code": 200,
"status": "success",
"message": "success",
"data": [
{
"currentDay": "2021-03-30",
"pcPlayDuration": 0,
"formatPcPlayDuration": "00:00:00",
"pcPlayDurationVideoAvg": 0,
"formatPcPlayDurationVideoAvg": "00:00:00",
"pcPlayDurationPersonAvg": 0,
"formatPcPlayDurationPersonAvg": "00:00:00",
"mobilePlayDuration": 0,
"formatMobilePlayDuration": "00:00:00",
"mobilePlayDurationVideoAvg": 0,
"formatMobilePlayDurationVideoAvg": "00:00:00",
"mobilePlayDurationPersonAvg": 0,
"formatMobilePlayDurationPersonAvg": "00:00:00"
},
{
"currentDay": "2021-03-31",
"pcPlayDuration": 1,
"formatPcPlayDuration": "00:00:01",
"pcPlayDurationVideoAvg": 1,
"formatPcPlayDurationVideoAvg": "00:00:01",
"pcPlayDurationPersonAvg": 1,
"formatPcPlayDurationPersonAvg": "00:00:01",
"mobilePlayDuration": 0,
"formatMobilePlayDuration": "00:00:00",
"mobilePlayDurationVideoAvg": 0,
"formatMobilePlayDurationVideoAvg": "00:00:00",
"mobilePlayDurationPersonAvg": 0,
"formatMobilePlayDurationPersonAvg": "00:00:00"
},
{
"currentDay": "2021-04-01",
"pcPlayDuration": 0,
"formatPcPlayDuration": "00:00:00",
"pcPlayDurationVideoAvg": 0,
"formatPcPlayDurationVideoAvg": "00:00:00",
"pcPlayDurationPersonAvg": 0,
"formatPcPlayDurationPersonAvg": "00:00:00",
"mobilePlayDuration": 0,
"formatMobilePlayDuration": "00:00:00",
"mobilePlayDurationVideoAvg": 0,
"formatMobilePlayDurationVideoAvg": "00:00:00",
"mobilePlayDurationPersonAvg": 0,
"formatMobilePlayDurationPersonAvg": "00:00:00"
}
]
}
异常示例
{
"code": 400,
"status": "error",
"message": "ptime is too old.",
"data": ""
}
