Batch Query Total Video Play Counts
Updated: 2025-01-14 16:13:58
Interface Description
1、通过视频id批量查询视频总播放次数
2、接口URL中的{userid}为点播账号userid,具体参考菜单【使用须知】->【获取密钥】
3、接口支持https协议
Interface URL
http://api.polyv.net/v2/data/{userid}/play-times
Request Method
POST
Interface Constraints
- The interface supports both HTTP and HTTPS. HTTPS is recommended to ensure interface security. Interface calls have 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 relayed through the customer's own server to call the POLYV server for response data. See signature generation rules |
| vids | true | String | Video IDs, separated by commas if multiple |
| realTime | false | String | Whether to query in real-time. Default is 0 if not passed. 1: Real-time 0: Non-real-time |
Example
http://api.polyv.net/v2/data/1b448be323/play-times
Form parameters:
vids=1b448be323dec2a7bed6db61bd7d8a77_1%2C1b448be323fb327a42539cbb788913b4_1&sign=E1D11A900807DBE2907E575BAB00A7C772FEC7E1&ptime=1617850155988
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 information returned on success. See data field description |
Data Parameter Description
| Parameter | Type | Description |
|---|---|---|
| vid | String | Video ID |
| times | Integer | Play count |
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. HttpUtil.java and VodSignUtil.java in the test cases are included 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 testGetVideoPlaytimes() throws Exception, NoSuchAlgorithmException {
//公共参数,填写自己的实际参数
String secretKey = super.secretKey;
String userId = super.userId;
String ptime = String.valueOf(System.currentTimeMillis());
//业务参数
String url = "http://api.polyv.net/v2/data/" + userId + "/play-times";
String vids = "1b448be323dec2a7bed6db61bd7d8a77_1,1b448be323fb327a42539cbb788913b4_1";
Map<String, String> requestMap = new HashMap<>();
requestMap.put("ptime", ptime);
requestMap.put("vids", vids);
requestMap.put("sign", VodSignUtil.getSign(requestMap, secretKey));
String response = HttpUtil.postFormBody(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":[
{
"vid":"1b448be323dec2a7bed6db61bd7d8a77_1",
"times":7
},
{
"vid":"1b448be323fb327a42539cbb788913b4_1",
"times":19
}
]
}
Error Example
{
"code": 400,
"status": "error",
"message": "ptime is too old.",
"data": ""
}
