Polyv Help Center

Help Center

Query Single Video View Completion

Updated: 2025-07-03 19:19:56

API Description

1、查询观众累计观看单个视频的完成度情况
2、数据的查询需要间隔一天,该接口需联系客服开通后才能使用
3、观看完成度=用户观看有效时长/视频时长,例如:视频A时长为50分钟,用户使用PC H5观看了第0~20分钟,又使用APP观看了第10~30分钟,此时用户有效观看时长为30分钟,则完成度为 30/50=60%
4、接口URL中的{userid}为点播账号userid,具体参考【获取密钥】
5、接口支持https协议

API URL

http://api.polyv.net/v2/video/engagement/{userid}/get

Online API Call

Request Method

GET

API Constraints

  1. The API supports both HTTP and HTTPS. HTTPS is recommended to ensure API security. API calls are subject to frequency limits. See details

Request Parameter Description

Parameter Required Type Description
ptime true Long Current time in milliseconds timestamp, valid within 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 and retrieve response data. See signature generation rules
vid true String Video ID
viewerId true String Custom viewer ID
queryBySpeed false String Whether to query view completion at playback speed, Y/N, default is N

Example

http://api.polyv.net/v2/video/engagement/1b448be323/get?vid=1b448be3230a0194d959426ae005645f_1%27&viewerId=1555313336634&sign=193CA2727C33AA5B439F2FD55C23C0BBC2DAAB4C&ptime=1617931245211

Response Parameter Description

Parameter Type Description
code Integer Response status code, 200 for success, non-200 for 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 Object Returns the video completion progress ratio on success, returns empty on failure

Error Code List

Error Code message Description
400 sign can not be empty. Signature string is empty
400 vid invalid. Invalid video vid
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. Userid does not exist
400 the sign is not right. Incorrect signature string
400 video not found Video not found
400 permission limit No permission to access the API

Java Request Example

For quick integration of basic code, 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(VodStatisticsTest.class);
/**
 * 查询单个视频的观看完成度
 */
@Test
public void testGetEngageStat() 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/video/engagement/%s/get", userId);
    String vid = "1b448be3230a0194d959426ae005645f_1'";
    String viewerId = "1555313336634";

    Map<String, String> requestMap = new HashMap<>();
    requestMap.put("ptime", ptime);
    requestMap.put("vid",vid);
    requestMap.put("viewerId", viewerId);
    requestMap.put("sign", VodSignUtil.getSign(requestMap, secretKey));

    String response = HttpUtil.get(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": 0.33
}

Error Example

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