Paginated Query of Channel Live Viewing Details
Interface Description
1、分页获取频道的直播观看日志
2、接口URL中的{channelId}为频道号
3、接口支持https协议
4、直播观看详情数据支持查询最近3年内的历史数据,建议将历史数据导出到本地储存,以便后续查询。
Interface URL
http://api.polyv.net/live/v2/statistics/{channelId}/viewlog
Request Method
GET
Interface Constraints
The interface supports both HTTP and HTTPS. HTTPS is recommended to ensure interface security. Interface calls have frequency limits. See details
To query records for a period, pass: startTime, endTime (startTime and endTime must be within the same month). To query records for a specific day, pass currentDay.
Unless the currentDay parameter is not empty, startTime and endTime are required parameters.
If currentDay is passed together with startTime and endTime, the values of startTime and endTime will take precedence.
Viewing duration data has a 3-5 minute delay.
Request Parameter Description
| Parameter | Required | Type | Description |
|---|---|---|---|
| appId | true | String | Account appId See details on obtaining keys] |
| timestamp | true | Long | Current 13-digit millisecond timestamp, valid for 3 minutes |
| sign | true | String | Signature, a 32-character uppercase MD5 value. The appSecret key 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 called through the customer's own server to relay requests to the POLYV server for response data. See signature generation rules |
| page | false | String | Current page number, defaults to 1 |
| pageSize | false | String | Number of data items per page, defaults to 1000 |
| startTime | false | String | Query start time, a 13-digit millisecond timestamp. Note: Unless the currentDay parameter is not empty, startTime and endTime are required parameters. |
| endTime | false | String | Query end time, a 13-digit millisecond timestamp. Note: Unless the currentDay parameter is not empty, startTime and endTime are required parameters. |
| currentDay | false | String | Query date, format: yyyy-MM-dd |
| param1 | false | String | Viewer user ID, defaults to querying all |
| param2 | false | String | Viewer nickname, defaults to querying all |
| param3 | false | String | Viewing log type, defaults to querying all vod: Viewing replay live: Live streaming |
| viewLogType | false | String | Live/VOD log type, defaults to live vod: Query VOD list viewing data live: Query live or replay list viewing data |
| sessionIds | false | String | Session IDs, multiple IDs separated by commas |
Example
http://api.polyv.net/live/v2/statistics/1965681/viewlog?currentDay=2021-1-20&appId=frlr1zazn3&sign=B16CE5B5F2FCCBDB37F4F374BB98B329&pageSize=10&startTime=1611072000000&page=1&endTime=1611158400000¶m3=live¶m1=1b448be323×tamp=1621842645601¶m2=%E7%AE%A1%E7%90%86%E5%91%98
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 reason when code is 400 or 500 |
| data | Object | Live viewing log information on success See Data parameter description], empty on failure |
Data Parameter Description
| Parameter | Type | Description |
|---|---|---|
| pageSize | Integer | Number of data items per page, defaults to 1000 |
| pageNumber | Integer | Current page number |
| totalItems | Integer | Total number of items |
| contents | Array | Query result list See Contents parameter description] |
| startRow | Integer | Position of the first record on the current page in the total result set |
| firstPage | Boolean | Whether it is the first page, value: true/false |
| lastPage | Boolean | Whether it is the last page, value: true/false |
| prePageNumber | Integer | Previous page number |
| nextPageNumber | Integer | Next page number |
| limit | Integer | Page size |
| totalPages | Integer | Total number of pages |
| endRow | Integer | Position of the last record on the current page in the total result set |
| offset | Integer | Pagination starting record |
Contents Parameter Description
| Parameter | Type | Description |
|---|---|---|
| playId | String | ID representing this playback action |
| userId | String | User ID |
| channelId | String | Channel number |
| playDuration | Integer | Playback duration, unit: seconds |
| stayDuration | Integer | Stay duration, unit: seconds |
| sessionId | String | Live session ID |
| param1 | String | Viewer ID from the POLYV viewing page |
| param2 | String | Viewer nickname from the POLYV viewing page |
| param3 | String | Viewing log type, defaults to live vod: Viewing replay live: Live streaming |
| param4 | String | POLYV system parameter |
| param5 | String | POLYV system parameter |
| ipAddress | String | IP address |
| country | String | Country |
| province | String | Province |
| city | String | City |
| isp | String | ISP operator |
| referer | String | Video playback page URL |
| userAgent | String | User device |
| operatingSystem | String | Operating system |
| browser | String | Browser |
| isMobile | String | Whether it is a mobile device |
| currentDay | String | Query date, format: yyyy-MM-dd |
| ptype | Integer | 0 or not passed: Normal live streaming 1: Ultra-low latency live streaming rts (no longer in use) 2: PRTC live streaming (no latency) |
| firstActiveTime | Long | Entry time, 13-digit millisecond timestamp |
| lastActiveTime | Long | Exit time, 13-digit millisecond timestamp |
Java Request Example
For quick integration of basic code, please download the relevant dependency source code. Click here to download the source code. Add it to your own source code project after downloading. HttpUtil.java and LiveSignUtil.java in the test cases are included in the downloaded file.
It is strongly recommended that you use the Live Java SDK for API integration. The Live 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(ChannelViewDataTest.class);
/**
* 分页查询频道直播观看详情数据
* @throws IOException
*/
@Test
public void testPageViewlog() throws IOException, NoSuchAlgorithmException {
//公共参数,填写自己的实际参数
String appId = super.appId;
String appSecret = super.appSecret;
String userId = super.userId;
String timestamp = String.valueOf(System.currentTimeMillis());
//业务参数
String url = String.format("http://api.polyv.net/live/v2/statistics/%s/viewlog","1965681");
String currentDay = "2021-1-20";
String page = "1";
String pageSize = "10";
String startTime = "1611072000000";
String endTime = "1611158400000";
String param1 = "1b448be323";
String param2 = "管理员";
String param3 = "live";
//http 调用逻辑
Map<String,String> requestMap = new HashMap<>();
requestMap.put("appId", appId);
requestMap.put("timestamp",timestamp);
requestMap.put("currentDay",currentDay);
requestMap.put("page",page);
requestMap.put("pageSize",pageSize);
requestMap.put("startTime",startTime);
requestMap.put("endTime",endTime);
requestMap.put("param1",param1);
requestMap.put("param2",param2);
requestMap.put("param3",param3);
requestMap.put("sign",LiveSignUtil.getSign(requestMap, appSecret));
String response = HttpUtil.get(url, requestMap);
log.info("测试分页查询频道直播观看详情数据,返回值:{}",response);
//do somethings
}
Response Example
For global system error descriptions, see Global Error Description
Success Example
{
"code":200,
"status":"success",
"message":"",
"data":{
"pageSize":10,
"pageNumber":1,
"totalItems":2,
"contents":[
{
"playId":"1611137360114X1320926",
"userId":"1b448be323",
"channelId":1965681,
"playDuration":182,
"stayDuration":190,
"sessionId":"fv3ma84e63",
"param1":"1b448be323",
"param2":"管理员",
"param3":"live",
"param4":"",
"param5":"",
"ipAddress":"118.249.213.240",
"country":"中国",
"province":"湖南",
"city":"长沙",
"isp":"湖南电信",
"referer":"https://live.polyv.net/#/channel/1965681/monitoring",
"userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0",
"operatingSystem":"Windows",
"browser":"Firefox 8",
"isMobile":"N",
"currentDay":"2021-01-20",
"createdTime":1611137461000,
"lastModified":1611148800000,
"ptype":0
},
{
"playId":"1611127231433X1037457",
"userId":"1b448be323",
"channelId":1965681,
"playDuration":154,
"stayDuration":160,
"sessionId":"fv3hmq3qml",
"param1":"1b448be323",
"param2":"管理员",
"param3":"live",
"param4":"",
"param5":"",
"ipAddress":"118.249.213.240",
"country":"中国",
"province":"湖南",
"city":"长沙",
"isp":"湖南电信",
"referer":"https://live.polyv.net/#/channel/1965681/monitoring",
"userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0",
"operatingSystem":"Windows",
"browser":"Firefox 8",
"isMobile":"N",
"currentDay":"2021-01-20",
"createdTime":1611127282000,
"lastModified":1611138733000,
"ptype":0
}
],
"startRow":1,
"firstPage":true,
"lastPage":true,
"prePageNumber":1,
"limit":2,
"totalPages":1,
"nextPageNumber":1,
"endRow":2,
"offset":0
}
}
Error Example
{
"code": 400,
"status": "error",
"message": "invalid signature.",
"data": ""
}
