Polyv Help Center

Help Center

Query Viewer Statistics

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

API Description

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

API URL

http://api.polyv.net/v2/data/visitor/{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 startDate and endDate must be passed together; passing only one parameter will not take effect.

  3. If both dr (time period) and startDate/endDate are passed, only startDate and endDate are effective. 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 stored or used directly on the client. 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
vid false String Video ID. If not passed, queries viewer statistics for all user videos
dr false String Time period, defaults to 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
startDate false String Start date, format yyyy-MM-dd, e.g., 2021-03-30
endDate false String End date, format yyyy-MM-dd, e.g., 2021-04-01

Example

http://api.polyv.net/v2/data/visitor/1b448be323?vid=1b448be323b8d9b9489dcd7e8e09f087_1&endDate=2021-04-01&sign=046BCEF4EC2BEA9E10E7CDF277203CFC849DE320&ptime=1617777987374&startDate=2021-03-30

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 Returns viewer statistics data on success, returns empty on failure. See data field description

Data Parameter Description

Field Type Description
date String Data generation date, format yyyy-MM-dd
pcUniqueViewer Integer Unique viewers on PC
mobileUniqueViewer Integer Unique viewers on mobile
totalUniqueViewer Integer Total unique viewers

Error Code List

Error Code Message Description
400 sign can not be empty. Signature is empty
400 ptime is too old. Timestamp expired
400 ptime is illegal. Timestamp 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. Signature is incorrect
401 start and end illegal. Start date is greater than end date

Java Request Example

For quick integration, 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 testGetViewerNumber() 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/visitor/%s", userId);
    String vid = "1b448be323b8d9b9489dcd7e8e09f087_1";
    String dr = "last_month";
    String startDate = "2021-03-30";
    String endDate = "2021-04-01";

    Map<String, String> requestMap = new HashMap<>();
    requestMap.put("ptime", ptime);
    requestMap.put("vid", vid);
    requestMap.put("startDate", startDate);
    requestMap.put("endDate", endDate);
    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": [
    {
      "date": "2021-03-30",
      "pcUniqueViewer": 0,
      "mobileUniqueViewer": 0,
      "totalUniqueViewer": 0
    },
    {
      "date": "2021-03-31",
      "pcUniqueViewer": 1,
      "mobileUniqueViewer": 0,
      "totalUniqueViewer": 1
    },
    {
      "date": "2021-04-01",
      "pcUniqueViewer": 0,
      "mobileUniqueViewer": 0,
      "totalUniqueViewer": 0
    }
  ]
}

Error Example

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