Polyv Help Center

Help Center

Query Viewer Analytics

Updated: 2025-01-14 16:24:03

API Description

1、通过观众id查询观众分析
2、接口URL中的{userid}为点播账号userid,具体参考【获取密钥】
3、接口支持https协议

API URL

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

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 have frequency limits. See details
  2. For advanced analytics features, see: Video Advanced Analytics
  3. Due to data volume and computation load, analytics results are available for query the next day.

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 and 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
viewerId true String Custom viewer ID

Example

http://api.polyv.net/v2/advance/viewer/1b448be323?viewerId=1555313336634&sign=2178D4B940BA22F790D642341947E87631C7C455&ptime=1617790781595

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, provides error details when code is 400 or 500
data Object Viewer analytics detailed data on success See data field description

data Field Description

Parameter Type Description
userId String POLYV user ID, same as on the Polyv official website. Path: Official Website -> Login -> Video on Demand (API)
viewerId String Viewer ID
viewerNickName String Viewer nickname
viewerAatar String Viewer avatar
ip String IP address
firstWatchTime Long First watch time, 13-digit millisecond timestamp
lastWatchTime Long Last watch time, 13-digit millisecond timestamp
totalVideoCount Integer Total number of videos watched
totalWatchDuration Integer Total watch duration, in seconds
avgCompletionRate Double Average watch completion rate
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 error
401 viewerId is blank. viewerId is empty
402 cannot find the viewer analytics data. Cannot find corresponding viewer analytics data
403 get viewer analytics failed. Failed to query viewer analytics data
500 get viewer analytics 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 to download source code. After downloading, add it to your own source project. HttpUtil.java and VodSignUtil.java in the test cases are included in the download file.

It is strongly recommended to use the Video on Demand 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 testGetViewerAnalysis() 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/viewer/%s", userId);
    String viewerId = "1555313336634";

    Map<String, String> requestMap = new HashMap<>();
    requestMap.put("ptime", ptime);
    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 global system error descriptions, see Global Error Description

Success Example

{
    "code": 200,
    "status": "success",
    "message": "success",
    "data": {
        "userId": "1b448be323",
        "viewerId": "1555313336634",
        "viewerNickName": "polyv_user_junit",
        "viewerAatar": null,
        "ip": "xxxxxxx",
        "firstWatchTime": 1617014826000,
        "lastWatchTime": 1617014871000,
        "totalVideoCount": 1,
        "totalWatchDuration": 68,
        "avgCompletionRate": 0.261
    }
}

Error Example

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