Polyv Help Center

Help Center

Query Viewing Behavior Analysis

Updated: 2025-01-14 16:23:01

API Description

1、通过时间区间分页查询观看行为分析数据
2、接口URL中的{userid}为点播账号userid,具体参考菜单【使用须知】->【获取密钥】
3、观看完成度=用户观看有效时长/视频时长,例如:视频A时长为50分钟,用户观看了第0~20分钟,拖拽进度条后观看了第10~30分钟,此时用户有效观看时长为30分钟,则完成度为 30/50=60%
4、接口支持https协议

API URL

http://api.polyv.net/v2/advance/play/{userid}

Online API Call

Request Method

GET

API Constraints

  1. The API supports both HTTP and HTTPS. HTTPS is recommended to ensure security. API calls have frequency limits. See details
  2. For advanced analysis features, see: Video Advanced Analysis
  3. Due to large data volume and computation, analysis results are available the next day.
  4. The query time span must not exceed 31 days. When start has a value and end is empty, data from 31 days after the start date is returned. When start is empty and end has a value, data from 31 days before the end date is returned. When both start and end are empty, data from the last 31 days is returned.

Request Parameter Description

Parameter Required Type Description
ptime true Long Current time in milliseconds, valid for 3 minutes
sign true String Signature, a 40-character uppercase SHA1 value. The secretkey used to generate the signature is critical for communication data security. It must never be saved or used directly on the client side. All APIs must be called through the customer's own server to relay requests to the POLYV server for response data. See signature generation rules
start false String Start time, format: yyyy-MM-dd or yyyy-MM-dd HH:mm:ss, query range not exceeding 31 days
end false String End time, format: yyyy-MM-dd or yyyy-MM-dd HH:mm:ss, query range not exceeding 31 days
pageSize false Integer Number of records per page (max 20, defaults to 20 if exceeded)
viewerId false String Custom viewer ID
viewerName false String Viewer nickname
vid false String Video ID. If not provided, returns viewing behavior analysis data for all videos under the current account
token false String Credential for the next page, obtained from the current page's response data. Not required for the first page

Example

http://api.polyv.net/v2/advance/play/1b448be323?vid=1b448be323ae991b1dfc5136597618d1_1&start=2021-03-10+15%3A21%3A01&sign=12BD21B68CE506562F6C79B7615254EB668B2DFB&pageSize=5&end=2021-04-07+15%3A21%3A01&ptime=1617786046170

Response Parameter Description

Parameter Type Description
code Integer Response status code. 200 indicates success, non-200 indicates failure. See global error description
status String Response status text
message String Response description. When code is 400 or 500, provides additional error details
data Object Returns detailed viewing behavior analysis data on success. See data field description

data Field Description

Parameter Type Description
pageSize Integer Number of records displayed per page
contents Array Detailed viewing data. See contents field description
token String Credential for querying the next page
hasNextPage Boolean Whether there is a next page

contents Field Description

Parameter Type Description
startTime String First viewing date, format: yyyy-MM-dd HH:mm:ss
videoId String Video ID
videoName String Video name
videoImage String Video thumbnail URL (without protocol header)
videoDuration Integer Video duration, in seconds
deviceClass String Device name
osName String Operating system
osVersion String Operating system version
agentName String Client name
agentVersion String Client version
referer String Referrer
ip String IP address
country String Country
province String Province
city String City
isp String ISP
viewerid String Viewer ID
viewerNickName String Viewer nickname
viewerAvatar String Viewer avatar
totalVideoCount Long Total number of videos watched by the viewer
heatmap String Heatmap (e.g., ["0-1:1","3-4:2"] means 1 view from 0 to 1 second, 2 views from 3 to 4 seconds)
completionRate Double Viewing completion rate
status String Video status
60/61: Published
10: Waiting for encoding
20: Encoding
50: Pending review
51: Review failed
-1: Deleted
playId String ID representing this playback action
Error Code List
Error Code message Description
400 sign can not be empty. Encryption string is empty
400 ptime is too old. Timestamp expired
400 ptime is illegal. ptime exceeds current time by 3 minutes
400 Could not find user by userid. userid does not exist
400 the sign is not right. Encryption string is incorrect
401 start date or end date is illegal. start or end parameter format is invalid
402 date range exceeds 31 days. start and end parameters differ by more than 31 days
403 get play list error. Backend failed to retrieve data
500 get play list failed. please check the backend log. Backend exception

Java Request Example

For quick integration of basic code, please download the relevant dependency source code. Click here to download the source code. After downloading, add it to your own source code project. The test cases include HttpUtil.java and VodSignUtil.java in the downloaded file.

It is strongly recommended to use the VOD Java SDK for API integration. The VOD Java SDK provides unified encapsulation and optimization for API call logic, exception handling, data signing, and HTTP request thread pools.

private static final Logger log = LoggerFactory.getLogger(VodBigdataTest.class);

/**
 * 查询观看行为分析
 */
@Test
public void testGetPlayAnalysis() 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/advance/play/%s", userId);
    String start = "2021-03-10 15:21:01";
    String end = "2021-04-07 15:21:01";
    String pageSize = "5";
    String vid = "1b448be323ae991b1dfc5136597618d1_1";

    Map<String, String> requestMap = new HashMap<>();
    requestMap.put("ptime", ptime);
    requestMap.put("start", start);
    requestMap.put("end", end);
    requestMap.put("pageSize", pageSize);
    requestMap.put("vid", vid);

    requestMap.put("sign", VodSignUtil.getSign(requestMap, secretKey));
    
    String response = HttpUtil.get(url, requestMap);
    log.debug("测试查询观看行为分析,{}", response);
    //do somethings
}

Response Example

For global error descriptions, see Global Error Description

Success Example

{
    "code": 200,
    "status": "success",
    "message": "success",
    "data": {
        "pageSize": 5,
        "contents": [{
            "startTime": "2021-04-06 16:29:06",
            "videoId": "1b448be323ae991b1dfc5136597618d1_1",
            "videoName": "小猫2",
            "videoImage": "//img.videocc.net/uimage/1/1b448be323/first_image/cd09cde7-acb0-4662-b24d-fee4b4e3f885_s.jpg",
            "videoDuration": 15,
            "deviceClass": "Desktop",
            "osName": "Windows NT",
            "osVersion": "10.0",
            "agentName": "Edge",
            "agentVersion": "89.0.774.68",
            "referer": "https://share.plvideo.cn/front/video/preview?vid=1b448be323ae991b1dfc5136597618d1_1",
            "ip": "xxxxxxx",
            "country": "中国",
            "province": "湖南",
            "city": "长沙",
            "isp": "中国电信",
            "viewerId": "N/A",
            "viewerNickName": "N/A",
            "viewerAvatar": "N/A",
            "totalVideoCount": 0,
            "heatmap": "[\"0-15:1\"]",
            "completionRate": 1.0,
            "status": 61,
            "playId": "1617697736110X1071695"
        }, {
            "startTime": "2021-04-02 17:11:48",
            "videoId": "1b448be323ae991b1dfc5136597618d1_1",
            "videoName": "小猫2",
            "videoImage": "//img.videocc.net/uimage/1/1b448be323/first_image/cd09cde7-acb0-4662-b24d-fee4b4e3f885_s.jpg",
            "videoDuration": 15,
            "deviceClass": "Desktop",
            "osName": "Windows NT",
            "osVersion": "10.0",
            "agentName": "Edge",
            "agentVersion": "89.0.774.63",
            "referer": "https://share.plvideo.cn/front/video/preview?vid=1b448be323ae991b1dfc5136597618d1_1",
            "ip": "xxxxxxx",
            "country": "中国",
            "province": "湖南",
            "city": "长沙",
            "isp": "中国电信",
            "viewerId": "N/A",
            "viewerNickName": "N/A",
            "viewerAvatar": "N/A",
            "totalVideoCount": 0,
            "heatmap": "[\"0-15:1\"]",
            "completionRate": 1.0,
            "status": 61,
            "playId": "1617354698104X1597608"
        }, {
            "startTime": "2021-03-31 16:28:14",
            "videoId": "1b448be323ae991b1dfc5136597618d1_1",
            "videoName": "小猫2",
            "videoImage": "//img.videocc.net/uimage/1/1b448be323/first_image/cd09cde7-acb0-4662-b24d-fee4b4e3f885_s.jpg",
            "videoDuration": 15,
            "deviceClass": "Desktop",
            "osName": "Windows NT",
            "osVersion": "10.0",
            "agentName": "Edge",
            "agentVersion": "89.0.774.63",
            "referer": "https://share.plvideo.cn/front/video/preview?vid=1b448be323ae991b1dfc5136597618d1_1",
            "ip": "xxxxxxx",
            "country": "中国",
            "province": "湖南",
            "city": "长沙",
            "isp": "中国电信",
            "viewerId": "N/A",
            "viewerNickName": "N/A",
            "viewerAvatar": "N/A",
            "totalVideoCount": 0,
            "heatmap": "[\"0-15:1\"]",
            "completionRate": 1.0,
            "status": 61,
            "playId": "1617179283819X1803923"
        }, {
            "startTime": "2021-03-31 16:26:10",
            "videoId": "1b448be323ae991b1dfc5136597618d1_1",
            "videoName": "小猫2",
            "videoImage": "//img.videocc.net/uimage/1/1b448be323/first_image/cd09cde7-acb0-4662-b24d-fee4b4e3f885_s.jpg",
            "videoDuration": 15,
            "deviceClass": "Phone",
            "osName": "Android",
            "osVersion": "6.0",
            "agentName": "WeChat",
            "agentVersion": "8.0.2.1860",
            "referer": "https://share.plvideo.cn/front/video/view?vid=1b448be323ae991b1dfc5136597618d1_1",
            "ip": "xxxxxxx",
            "country": "中国",
            "province": "湖南",
            "city": "长沙",
            "isp": "中国电信",
            "viewerId": "N/A",
            "viewerNickName": "N/A",
            "viewerAvatar": "N/A",
            "totalVideoCount": 0,
            "heatmap": "[\"0-15:1\"]",
            "completionRate": 1.0,
            "status": 61,
            "playId": "1617179158342X1197943"
        }, {
            "startTime": "2021-03-31 16:25:20",
            "videoId": "1b448be323ae991b1dfc5136597618d1_1",
            "videoName": "小猫2",
            "videoImage": "//img.videocc.net/uimage/1/1b448be323/first_image/cd09cde7-acb0-4662-b24d-fee4b4e3f885_s.jpg",
            "videoDuration": 15,
            "deviceClass": "Desktop",
            "osName": "Windows NT",
            "osVersion": "10.0",
            "agentName": "Edge",
            "agentVersion": "89.0.774.63",
            "referer": "https://share.plvideo.cn/front/video/preview?vid=1b448be323ae991b1dfc5136597618d1_1",
            "ip": "xxxxxxx",
            "country": "中国",
            "province": "湖南",
            "city": "长沙",
            "isp": "中国电信",
            "viewerId": "N/A",
            "viewerNickName": "N/A",
            "viewerAvatar": "N/A",
            "totalVideoCount": 0,
            "heatmap": "[\"0-15:1\"]",
            "completionRate": 1.0,
            "status": 61,
            "playId": "1617179110026X1812455"
        }],
        "token": "2daa82aabd892f661e967ed365536c05ad832deccda9d0a66f380c6987d838b8e248525ef721439b95a56f9d2027734e5b0d72bbb3022c88a2ef50e2604de902",
        "hasNextPage": true
    }
}

Error Example

{
  "code": 400,
  "status": "error",
  "message": "ptime is too old.",
  "data": ""
}
联系客服,在线咨询