Polyv Help Center

Help Center

Query Play Count Statistics

Updated: 2025-01-14 16:14:34

API Description

1、查询视频播放量在不同终端的统计数据,从播放行为产生到数据可查询的间隔时间为1~2小时
2、接口URL中的{userid}为点播账号userid,具体参考菜单【使用须知】->【获取密钥】
3、接口支持https协议

API URL

http://api.polyv.net/v2/videoview/{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 value of the request parameter period (display cycle) is constrained by the value of dr. When dr is today, yesterday, this_week, last_week, or 7days, period can only be daily. When dr is this_month or last_month, period can only be daily or weekly.

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 stored 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
vid false String Video ID. If not provided, play count statistics for all videos will be queried.
dr false String Time range. Default is 7days.
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
period false String Display cycle. Default is daily.
daily: Display by day
weekly: Display by week
monthly: Display by month

Example

http://api.polyv.net/v2/videoview/1b448be323?vid=1b448be32395861bacc794ca59e8f306_1&sign=AD7527B17D2F2BE5E740F9D3357B7F80231837CE&ptime=1618215907432

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 Array of video play statistics data returned on success. See Data Field Description
Data Parameter Description
Parameter Type Description
currentTime String Current date, format: yyyy-MM-dd
pcVideoView Integer PC play count
mobileVideoView Integer Mobile play count

Error Code List

Error Code message Description
400 sign can not be empty. Signature string is empty
400 ptime is too old. Timestamp has 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. Signature string is incorrect
401 illegal vid. Video ID format is incorrect. The correct format starts with the user ID.
402 illegal period. Period value is invalid. Refer to the period constraints in the request parameters.
500 query failed. Backend program threw an exception

Java Request Example

For quick integration, please download the relevant dependency source code. Click here to download the 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 testGetPlaytimes() throws Exception, NoSuchAlgorithmException {
    //公共参数,填写自己的实际参数
    String secretKey = super.secretKey;
    String userId = super.userId;
    String ptime = String.valueOf(System.currentTimeMillis());
    //业务参数
    String url = "http://api.polyv.net/v2/videoview/" + userId;
    String vid = "1b448be32395861bacc794ca59e8f306_1";

    Map<String, String> requestMap = new HashMap<>();
    requestMap.put("ptime", ptime);
    requestMap.put("vid", vid);
    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":[
        {
            "currentTime":"2021-04-06",
            "pcVideoView":0,
            "mobileVideoView":0
        },
        {
            "currentTime":"2021-04-07",
            "pcVideoView":0,
            "mobileVideoView":0
        },
        {
            "currentTime":"2021-04-08",
            "pcVideoView":0,
            "mobileVideoView":0
        },
        {
            "currentTime":"2021-04-09",
            "pcVideoView":0,
            "mobileVideoView":0
        },
        {
            "currentTime":"2021-04-10",
            "pcVideoView":0,
            "mobileVideoView":0
        },
        {
            "currentTime":"2021-04-11",
            "pcVideoView":0,
            "mobileVideoView":0
        },
        {
            "currentTime":"2021-04-12",
            "pcVideoView":0,
            "mobileVideoView":0
        }
    ]
}

Error Example

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