Polyv Help Center

Help Center

Query Play Duration Statistics

Updated: 2025-01-14 16:15:31

API Description

1、通过视频id和时间范围查询单个或全部视频的播放时长统计数据,播放后生成数据需间隔一到两小时
2、接口URL中的{userid}为点播账号userid,具体参考菜单【使用须知】->【获取密钥】
3、接口支持https协议

API URL

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

Online API Call

Request Method

GET

API Constraints

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

  2. The request parameters start (start date) and end (end date) must be passed together. Passing only one parameter will not take effect.

  3. If both dr (time range) and start/end are passed, only start and end are valid. If none are passed, dr defaults to 7days.

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 secret key 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 and obtain response data. See signature generation rules
vid false String Video ID. If not passed, query play duration data for all user videos
dr false String Time range, default value is 7days (last 7 days)
today: Today
yesterday: Yesterday
this_week: This week
last_week: Last week
7days: Last 7 days
this_month: This month
last_month: Last month
this_year: This year
last_year: Last year
start false String Start date, format: yyyy-MM-dd, e.g., 2021-03-30
end false String End date, format: yyyy-MM-dd, e.g., 2021-04-01

Example

http://api.polyv.net/v2/play-duration/1b448be323?vid=1b448be323b8d9b9489dcd7e8e09f087_1&start=2021-03-30&sign=645AB5A43A556E6D6AF8A577C287266E0BC822D1&end=2021-04-01&ptime=1617767033059

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 auxiliary error reason
data Array On success, returns video play duration statistics data. On failure, returns empty. See data field description

Data Parameter Description

Field Type Description
currentDay String Data generation date, format: yyyy-MM-dd
pcPlayDuration Integer PC play duration, in seconds
formatPcPlayDuration String Formatted PC play duration, format: HH:mm:ss
pcPlayDurationVideoAvg Integer Average PC video play duration, in seconds
formatPcPlayDurationVideoAvg String Formatted average PC video play duration, format: HH:mm:ss
pcPlayDurationPersonAvg Integer Average PC play duration per person, in seconds
formatPcPlayDurationPersonAvg String Formatted average PC play duration per person, format: HH:mm:ss
mobilePlayDuration Integer Mobile play duration, in seconds
formatMobilePlayDuration String Formatted mobile play duration, format: HH:mm:ss
mobilePlayDurationVideoAvg Integer Average mobile video play duration, in seconds
formatMobilePlayDurationVideoAvg String Formatted average mobile video play duration, format: HH:mm:ss
mobilePlayDurationPersonAvg Integer Average mobile play duration per person, in seconds
formatMobilePlayDurationPersonAvg String Formatted average mobile play duration per person, format: HH:mm:ss

Error Code List

Error Code message Description
400 ptime is too old. Timestamp expired
400 ptime is illegal. Timestamp parameter format is incorrect or exceeds current time by 3 minutes
400 Could not find user by userid. User ID does not exist
400 the sign is not right. Incorrect signature string
401 start and end illegal. Start date is greater than end date

Java Request Example

For quick integration of basic code, please download the relevant dependency source code. Click here to download 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 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
    
}

Response Example

For global system error descriptions, see Global Error Description

Success Example

{
    "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"
        }
    ]
}

Error Example

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