Polyv Help Center

Help Center

Batch Query Video Watch Logs

Updated: 2025-01-14 16:21:46

API Description

1、通过自然月批量获取视频观看日志
2、从播放行为产生到数据可查询的间隔时间为1~2小时
3、响应参数消耗流量(flowSize字段)的计算依赖于CDN日志,为了保证数据完整性,流量数据需要间隔一个自然日才会生成
4、接口URL中的{userid}为点播账号userid,具体参考【获取密钥】
5、接口URL中的{month}为查询月份,格式:yyyyMM
6、接口支持https协议

API URL

http://api.polyv.net/v2/viewlog/{userid}/monthly/{month}

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

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
month true Integer Query month data, format: yyyyMM, e.g., 202101
numPerPage false Integer Number of items per page, default is 99
pageNum false Integer Page number, default is 1
start false String Query start date, format: yyyy-MM-dd, e.g., 2021-01-01
end false String Query end date, format: yyyy-MM-dd, e.g., 2021-01-05
vid false String Video ID. When empty, query logs for all videos of the user
sessionId false String Custom user ID
currentDay false String Data for a specific day within the month, format: yyyy-MM-dd, e.g., 2021-01-01

Example

http://api.polyv.net/v2/viewlog/1b448be323/monthly/202104?currentDay=2021-04-07&month=202104&sign=504AD715A14CE68DA568B2935953A1796994B3D1&numPerPage=2&ptime=1617852294166&pageNum=1

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 Array Log details returned on success. See data field description
total Integer Total number of records

Data Field Description

Parameter Type Description
playId String ID representing this playback action
userId String POLYV user ID, consistent with the POLYV official website. Path: Official Website -> Login -> VOD (API Interface)
videoId String Video ID
playDuration Integer Playback duration in seconds, independent of playback speed (total time the user watched, e.g., starting at 18:00 and watching until 18:30 equals 30 minutes)
stayDuration Integer Page stay duration in seconds, independent of whether the video is playing
currentTimes Integer Playback time in seconds (the last time the user watched, e.g., if the progress bar was at 35 minutes when stopped, the playback time is 35 minutes)
duration Integer Total video duration in seconds
flowSize Long Traffic size in bytes
sessionId String Custom user parameter, e.g., student ID
param1/2/3/4/5 String POLYV system parameters
ipAddress String IP address
country String Country
province String Province
city String City
isp String ISP provider
referer String URL of the page playing the video
userAgent String User device
operatingSystem String Operating system
browser String Browser
isMobile String Whether it is a mobile device
Y: Yes
N: No
currentDay String Log query date, format: yyyy-MM-dd
currentHour Integer Log creation time (24-hour format hour), e.g., 18 means 6 PM
viewSource String User viewing channel
vod_ios_sdk: iOS
vod_android_sdk: Android
vod_flash: Flash
vod_wechat_mini_program: WeChat Mini Program
vod_pc_html5: PC web
vod_mobile_html5: Mobile web
vod_mobile_html5_v2: Mobile web v2
polyv-android-sdk: Android screen casting
polyv-ios-vod-sdk: iOS screen casting
createdTime Long Log creation time, 13-digit millisecond timestamp
lastModified Long Log update time, 13-digit millisecond timestamp
viewerId String Viewer ID
viewerName String Viewer name
Error Code List
Error Code message Description
400 ptime is illegal. Timestamp format issue or timestamp exceeds current time by 3 minutes
400 sign can not be empty. Signature string is empty
400 Could not find user by userid. User ID does not exist
400 ptime is too old. Timestamp expired (expires after 3 minutes)
400 the sign is not right. Signature string is incorrect
401 pageNum and numPerPage must be positive integers greater than 0. Pagination parameters are incorrect
402 month must be in valid yyyyMM format. Month format is incorrect
500 Query failed. Backend error occurred

Java Request Example

For quick integration, please download the relevant dependency source code. Click here to download the source code. After downloading, add it to your own source 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(VodStatisticsTest.class);

/**
 * 批量查询视频观看日志
 * @throws Exception
 * @throws NoSuchAlgorithmException
 */
@Test
public void testGetViewlog() throws Exception, NoSuchAlgorithmException {
    //公共参数,填写自己的实际参数
    String secretKey = super.secretKey;
    String userId = super.userId;
    String ptime = String.valueOf(System.currentTimeMillis());
    //业务参数
    String month = "202104";
    String url = String.format("http://api.polyv.net/v2/viewlog/%s/monthly/%s", userId, month);
    String currentDay = "2021-04-07";
    String numPerPage = String.valueOf(2);
    String pageNum = String.valueOf(1);

    Map<String, String> requestMap = new HashMap<>();
    requestMap.put("ptime", ptime);
    requestMap.put("currentDay", currentDay);
    requestMap.put("month", month);
    requestMap.put("numPerPage", numPerPage);
    requestMap.put("pageNum", pageNum);
    requestMap.put("sign", VodSignUtil.getSign(requestMap, secretKey));

    String response = HttpUtil.get(url, requestMap);
    log.debug("测试批量查询视频观看日志,{}", response);
    //do somethings
}

Response Example

For global system error descriptions, see Global Error Description

Success Example

{
    "code": 200,
    "status": "success",
    "message": "success",
    "data": [{
        "playId": "1617791143803X1210954",
        "userId": "1b448be323",
        "videoId": "1b448be323a146649ad0cc89d0faed9c_1",
        "playDuration": 21,
        "stayDuration": 30,
        "currentTimes": 22,
        "duration": 191,
        "flowSize": 0,
        "sessionId": "",
        "param1": "",
        "param2": "",
        "param3": "",
        "param4": "",
        "param5": "",
        "ipAddress": "xxxxxxx",
        "country": "中国",
        "province": "湖南",
        "city": "长沙",
        "isp": "湖南电信",
        "referer": "https://share.plvideo.cn/front/video/preview?vid=1b448be323a146649ad0cc89d0faed9c_1",
        "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36",
        "operatingSystem": "Windows",
        "browser": "Chrome",
        "isMobile": "N",
        "currentDay": "2021-04-07",
        "currentHour": 18,
        "createdTime": 1617791314000,
        "lastModified": 1617802680000,
        "viewerId": "",
        "viewerName": "",
        "viewSource": "vod_pc_html5"
    }, {
        "playId": "1617791015552X1409047",
        "userId": "1b448be323",
        "videoId": "1b448be323a146649ad0cc89d0faed9c_1",
        "playDuration": 33,
        "stayDuration": 40,
        "currentTimes": 35,
        "duration": 191,
        "flowSize": 0,
        "sessionId": "",
        "param1": "",
        "param2": "",
        "param3": "",
        "param4": "",
        "param5": "",
        "ipAddress": "xxxxxxx",
        "country": "中国",
        "province": "湖南",
        "city": "长沙",
        "isp": "湖南电信",
        "referer": "https://share.plvideo.cn/front/video/preview?vid=1b448be323a146649ad0cc89d0faed9c_1",
        "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36",
        "operatingSystem": "Windows",
        "browser": "Chrome",
        "isMobile": "N",
        "currentDay": "2021-04-07",
        "currentHour": 18,
        "createdTime": 1617791294000,
        "lastModified": 1617802668000,
        "viewerId": "",
        "viewerName": "",
        "viewSource": "vod_pc_html5"
    }],
    "total": 8
}

Error Example

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