Polyv Help Center

Help Center

Query Video Viewing Logs for a Specific Day

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

API Description

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

API URL

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

Online API Call

Request Method

POST

API Constraints

  1. The API supports both HTTP and HTTPS. HTTPS is recommended to ensure API security. API calls have frequency limits. Click for details

  2. The concatenation rule for sign (signature) is: userid=parameter&ptime=parameter&day=parametersecretkey, and it is passed along with sign via the URL.

Request Parameter Description

Parameter Required Type Description
ptime true Long Current time in milliseconds timestamp, 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 not be 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
day true String Specific date for querying log information, format: yyyyMMdd, e.g., 20210407
timeStart false String Range query, specific time (hours, minutes, seconds) for log information, format: HHmmss, e.g., 000000. timeStart and timeEnd must be used together.
timeEnd false String Range query, specific time (hours, minutes, seconds) for log information, format: HHmmss, e.g., 235959. timeStart and timeEnd must be used together.
type false String Return data format, default is JSON.
xml: returns XML format
json: returns JSON format
vid false String Video ID
cataid false String Category ID. Note: When both video ID and category ID are empty, all video logs for the account on that day are retrieved. When video ID is empty and category ID is not empty, logs under the corresponding category are queried. When video ID is not empty, logs for the corresponding video are queried.
sessionId false String Custom user ID
viewerId false String Custom user ID. When passed together with sessionId, viewerId takes precedence.

Example

http://api.polyv.net/v2/data/1b448be323/viewlog

Form Parameters:

vid=1b448be323615635294a548b3c8a9953_1&sign=AD77F4AFEFA3D3DE07BDD31503A363A21D1A4536&cataid=1602671097888&type=json&ptime=1617847185866&day=20210407

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, it provides auxiliary error reason description.
data Array Detailed log information returned upon successful response. See data Field Description

data Field Description

Parameter Type Description
playId String ID representing this playback action
userId String POLYV user ID, consistent with the POLYV official website. Retrieval path: Official Website -> Login -> On-Demand (API Interface)
videoId String Video ID
playDuration Integer Playback duration in seconds (total time the user watched, e.g., starting a video at 18:00 and watching until 18:30, the 30 minutes is the playback duration)
stayDuration Integer Cache duration in seconds
currentTimes Integer Playback time in seconds (the last time the user watched, e.g., if the progress bar was at 35 minutes when the user stopped watching, 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 operator
referer String Video playback page URL
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, indicates created at 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
vod_wechat_plugin: Mini Program Plugin
createdTime Long Log creation time, 13-digit millisecond timestamp
lastModified Long Log update date, 13-digit millisecond timestamp
viewerId String Viewer ID
viewerName String Viewer name

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 case files HttpUtil.java and VodSignUtil.java are included in the download package.

It is strongly recommended to use the VOD Java SDK for API integration. The VOD Java SDK provides a 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 testGetDailyViewlog() 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/data/%s/viewlog", userId);
    String day = "20210407";
    String type = "json";
    String vid = "1b448be323615635294a548b3c8a9953_1";
    String cataid = "1602671097888";

    Map<String, String> requestMap = new HashMap<>();
    requestMap.put("ptime", ptime);
    requestMap.put("day", day);
    requestMap.put("type", type);
    requestMap.put("vid", vid);
    requestMap.put("cataid", cataid);

    //系统只对部分参数进行签名
    Map<String, String> signMap = new HashMap<>();
    signMap.put("userid", userId);
    signMap.put("ptime", ptime);
    signMap.put("day", day);
    requestMap.put("sign", VodSignUtil.getSign(signMap, secretKey));

    String response = HttpUtil.postFormBody(url, requestMap);
    log.debug("测试查询某一天的视频观看日志,{}", response);
    //do somethings
}

Response Example

For system-wide global error descriptions, see Global Error Description

Success Example

{
    "code": 200,
    "status": "success",
    "message": "success",
    "data": [{
        "playId": "1617789715498X1074620",
        "userId": "1b448be323",
        "videoId": "1b448be323615635294a548b3c8a9953_1",
        "playDuration": 6,
        "stayDuration": 10,
        "currentTimes": 2,
        "duration": 11,
        "flowSize": 0,
        "sessionId": "",
        "param1": "",
        "param2": "",
        "param3": "",
        "param4": "",
        "param5": "",
        "ipAddress": "xxxxxxx",
        "country": "中国",
        "province": "湖南",
        "city": "长沙",
        "isp": "湖南电信",
        "referer": "https://share.plvideo.cn/front/video/preview?vid=1b448be323615635294a548b3c8a9953_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": 1617790069000,
        "lastModified": 1617800772000,
        "viewerId": "",
        "viewerName": "",
        "viewSource": "vod_pc_html5"
    }, {
        "playId": "1617766244609X1752092",
        "userId": "1b448be323",
        "videoId": "1b448be323615635294a548b3c8a9953_1",
        "playDuration": 7,
        "stayDuration": 10,
        "currentTimes": 10,
        "duration": 11,
        "flowSize": 0,
        "sessionId": "",
        "param1": "",
        "param2": "",
        "param3": "",
        "param4": "",
        "param5": "",
        "ipAddress": "xxxxxxx",
        "country": "中国",
        "province": "湖南",
        "city": "长沙",
        "isp": "湖南电信",
        "referer": "https://my.polyv.net/secure/video/",
        "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36 Edg/89.0.774.68",
        "operatingSystem": "Windows",
        "browser": "Chrome",
        "isMobile": "N",
        "currentDay": "2021-04-07",
        "currentHour": 11,
        "createdTime": 1617766571000,
        "lastModified": 1617777096000,
        "viewerId": "",
        "viewerName": "",
        "viewSource": "vod_pc_html5"
    }]
}

Error Example

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