Query Video Playback Viewing Ratio Distribution
API Description
1、通过视频id和时间范围查询单个视频或全部视频的观看比例统计数据,播放后生成数据需间隔一到两小时
2、接口URL中的{userid}为点播账号userid,具体参考【获取密钥】
3、接口支持https协议
API URL
http://api.polyv.net/v2/play-ratio/{userid}
Request Method
GET
API Constraints
The API supports both HTTP and HTTPS. HTTPS is recommended for security. API calls have frequency limits. See details
The request parameters
start(start date) andend(end date) must be passed together; passing only one parameter will not take effect.If both
dr(time period) andstart/endare passed, onlystartandendare valid. If none are passed,drdefaults to7days.
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. It must not be stored or used directly on the client. All APIs must be called through your own server to relay requests to the POLYV server for response data. See signature generation rules |
| vid | false | String | Video ID. If not passed, query the viewing ratio statistics for all videos of the user. |
| dr | false | String | Time period, default is 7days (last 7 days).today: Todayyesterday: Yesterdaythis_week: This weeklast_week: Last week7days: Last 7 daysthis_month: This monthlast_month: Last monththis_year: This yearlast_year: Last year |
| start | false | String | Start date, format yyyy-MM-dd, e.g., 2021-03-01 |
| end | false | String | End date, format yyyy-MM-dd, e.g., 2021-04-02 |
Example
http://api.polyv.net/v2/play-ratio/1b448be323?start=2021-03-01&sign=F287BF9EB23F645CE478A891792AAA00F66F82E0&end=2021-04-02&ptime=1617845079462
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 | On success, returns video viewing ratio data. On failure, returns empty. See data field description |
data Parameter Description
| Field | Type | Description |
|---|---|---|
| percentage | String | Playback ratio range, in percentage |
| playCount | Integer | Play count |
Error Code List
| Error Code | message | Description |
|---|---|---|
| 400 | sign can not be empty. | Encryption string is empty |
| 400 | vid invalid. | Invalid video ID |
| 400 | ptime is too old. | Timestamp expired |
| 400 | ptime is illegal. | Invalid timestamp format 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. | Incorrect encryption string |
| 401 | start and end illegal. | Start date is greater than end date |
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. 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 testGetPlayTimesByRatio() throws Exception, NoSuchAlgorithmException {
//公共参数,填写自己的实际参数
String secretKey = super.secretKey;
String userId = super.userId;
String ptime = String.valueOf(System.currentTimeMillis());
//业务参数
String url = String.format("https://api.polyv.net/v2/play-ratio/%s", userId);
String vid = "1b448be323b8d9b9489dcd7e8e09f087_1";
String dr = "last_month";
String start = "2021-03-01";
String end = "2021-04-02";
Map<String, String> requestMap = new HashMap<>();
requestMap.put("ptime", ptime);
requestMap.put("start", start);
requestMap.put("end", end);
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": [
{
"percentage": "0-10",
"playCount": 57
},
{
"percentage": "10-20",
"playCount": 25
},
{
"percentage": "20-30",
"playCount": 28
},
{
"percentage": "30-40",
"playCount": 26
},
{
"percentage": "40-50",
"playCount": 12
},
{
"percentage": "50-60",
"playCount": 12
},
{
"percentage": "60-70",
"playCount": 19
},
{
"percentage": "70-80",
"playCount": 11
},
{
"percentage": "80-90",
"playCount": 4
},
{
"percentage": "90-100",
"playCount": 28
}
]
}
Error Example
{
"code": 400,
"status": "error",
"message": "ptime is too old.",
"data": ""
}
