文章目录
接口URL
http://api.polyv.net/v2/advance/viewer/{userid}
接口说明
(接口调用有频率限制,详细请查看)
- 高级分析功能介绍详见: 视频高级分析。
- 由于数据量和计算量大,数据分析结果次日才可查询。
返回结果支持格式
JSON
请求方式
GET
请求参数
参数名 | 必选 | 类型及范围 | 说明 |
---|---|---|---|
ptime | true | string | 当前时间的毫秒级时间戳(13位),30分钟内有效 |
sign | true | string | 签名 |
userid | true | string | 用户id(拼接在url,无需另外传参数) |
viewerId | true | string | 观众id |
注意事项
所有有值的参数,按照字母排序方式以key=value&key=value的格式串起来,最后拼上secretkey,以SHA-1方式加密并全部大写化。(注意,当参数没有传递,或者传递了空值,sign不需要将此参数计算进去)
例如:api传递了ptime,vid。ptime为1,vid为test1,userid对应用户的secretkey为test2
则sign的值为:ptime=1&vid=test1test2经过SHA-1加密后大写化为: C2B1558D697EA3AF4ED2FC90152751860C1E2163。
返回错误结果JSON示例
{
"code": 400,
"status": "error",
"message": "ptime is too old.",
"data": ""
}
返回正确结果JSON示例
{
"code": 200,
"status": "success",
"message": "success",
"data": {
"userId": "xxxx",
"viewerId": "观众id",
"viewerNickName": "观众昵称",
"viewerAatar": null,
"ip": "127.0.0.1",
"firstWatchTime": 1547020140000,
"lastWatchTime": 1548148547000,
"totalVideoCount": 6,
"totalWatchDuration": 1870,
"avgCompletionRate": 0.519
}
}
返回结果data表示成功修改的数量.
字段说明
字段 | 说明 |
---|---|
code | 返回码 |
status | 返回状态 |
message | 返回信息 |
data | 操作结果 |
数据对象字段说明
字段 | 说明 |
---|---|
userId | 用户id |
viewerId | 观众id |
viewerNickName | 观众昵称 |
viewerAatar | 观众头像 |
ip | ip地址 |
firstWatchTime | 首次观看时间 |
lastWatchTime | 最后观看时间 |
totalVideoCount | 观看视频总数 |
totalWatchDuration | 观众总时长(秒) |
avgCompletionRate | 平均观看完成度 |
响应代码与响应信息对应
code | message | data | 说明 |
---|---|---|---|
400 | sign can not be empty. | 加密串为空 | |
400 | ptime is too old. | 时间戳过期 | |
400 | ptime is illegal. | ptime超出当前时间3分钟 | |
400 | Could not find user by userid. | userid不存在 | |
400 | the sign is not right. | 加密串错误 | |
401 | viewerId is blank. | viewerId为空 | |
402 | cannot find the viewer analytics data. | 查不到对应的观众分析数据 | |
403 | get viewer analytics failed. | 查询观众分析数据失败 | |
500 | get viewer analytics failed. please check the backend log | 后台抛异常 | |
200 | success | 查询到的数据 | 查询成功 |
PHP示例代码
<?php
header("Content-type: text/html; charset=utf-8");
$userid="3828390191";
//$jsonp="a";
$ptime=time()*1000;//13位
$viewerId="观众id";
$secretkey="secretkey";
if(empty($jsonp)){
$str="ptime=".$ptime."&viewerId=".$viewerId.$secretkey;
}else{
$str="jsonp=".$jsonp."&ptime=".$ptime."&viewerId=".$viewerId.$secretkey;
}
echo $str.'';
$hash=strtoupper(sha1($str));
echo $hash.'';
$url="http://api.polyv.net/v2/advance/viewer/{$userid}?viewerId={$viewerId}&ptime={$ptime}&sign={$hash}";
$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" = "1493188350000"
"playauth" = "1"
2、将请求参数按照参数名字典顺序排列
"playauth" = "1"
"ptime" = "1493188350000"
3、连接字符串
连接参数名与参数值,并在尾部加上secretkey(secretkey的值为tIQp4ATe9Z),如下:
playauth=1&ptime=1493188350000tIQp4ATe9Z
4、生成签名sign
7198CB4BAE7484C01EA1A1566D0210FF18EA1849