Query Multi-Session Overview Statistics for a Channel
Interface Description
1、接口用于统计直播间内多场次的直播的观看数据,数据会根据场次号进行汇总,返回观看UV、观看PV等。
2、接口支持https协议
3、需要在直播完成后一小时才生成最新场次的统计数据
Interface URL
http://api.polyv.net/live/v3/channel/statistics/get-session-stats
Request Method
GET
Interface Constraints
The interface supports both HTTP and HTTPS. HTTPS is recommended for security. API calls have frequency limits. See details
Either session IDs or the live broadcast start and end times must be provided. If both session IDs and time range are present, only session IDs will be used.
The interval between startTime and endTime must not exceed 30 days.
Watch duration is calculated by rounding up each watch record (less than 1 minute is counted as 1 minute) and then summing them. For example, a single watch record of 1 minute and 36 seconds will be counted as 2 minutes.
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 used directly on the client side. All APIs must be called through your own server to relay requests to the POLYV server for response data. See signature generation rules |
| channelId | true | String | Channel ID |
| sessionIds | false | String | Session IDs, multiple sessions separated by commas, e.g., fw82mayhuy,fvipafupmh. Either session IDs or live broadcast start and end times must be provided. If both exist, session IDs are used for querying. |
| startTime | false | Long | Live broadcast start time, 13-digit millisecond timestamp. The interval between start and end times must not exceed 30 days. |
| endTime | false | Long | Live broadcast end time, 13-digit millisecond timestamp. Either session IDs or live broadcast start and end times must be provided. |
Example
http://api.polyv.net/live/v3/channel/statistics/get-session-stats?appId=frlr1zazn3&sign=F4DF8748424C8FDCE3DBF9C96C134C1A&startTime=1621842273181&endTime=1621842273181&userId=1b448be323&channelId=1965681×tamp=1621842273181&sessionIds=ftmnaan4l3%2Cfv3ma84e63
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 details when code is 400 or 500 |
| data | Object | Live broadcast viewing data on success See Data parameter description, empty on failure |
Data Parameter Description
| Parameter | Type | Description |
|---|---|---|
| list | Array | List of viewing data for multiple sessions in the live room See List parameter description |
List Parameter Description
| Parameter | Type | Description |
|---|---|---|
| channelId | String | Channel ID |
| sessionId | String | Session ID |
| name | String | Session name |
| startTime | Long | Session start time, 13-digit millisecond timestamp |
| endTime | Long | Session end time, 13-digit millisecond timestamp |
| duration | Integer | Live broadcast duration, in seconds |
| liveUV | Integer | Number of unique live viewers |
| livePV | Integer | Number of live views |
| playbackUV | Integer | Number of unique playback viewers |
| playbackPV | Integer | Number of playback views |
| totalPlayDuration | Integer | Total live watch duration, in seconds |
| totalPlaybackDuration | Integer | Total playback watch duration, in seconds |
Java Request Example
For quick integration of basic code, please download the relevant dependency source code. Click to download source code. After downloading, add it to your own source project. The test cases include HttpUtil.java and LiveSignUtil.java in the downloaded file.
It is strongly recommended to 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 testGetSessionStats() throws IOException, NoSuchAlgorithmException {
//公共参数,填写自己的实际参数
String appId = super.appId;
String appSecret = super.appSecret;
String userId = super.userId;
String timestamp = String.valueOf(System.currentTimeMillis());
//业务参数
String url = "https://api.polyv.net/live/v3/channel/statistics/get-session-stats";
String channelId = "1965681";
String sessionIds = "ftmnaan4l3,fv3ma84e63";
String startTime = String.valueOf(System.currentTimeMillis());
String endTime = String.valueOf(System.currentTimeMillis());
//http 调用逻辑
Map<String,String> requestMap = new HashMap<>();
requestMap.put("appId", appId);
requestMap.put("timestamp",timestamp);
requestMap.put("userId",userId);
requestMap.put("channelId",channelId);
requestMap.put("sessionIds",sessionIds);
requestMap.put("startTime",startTime);
requestMap.put("endTime",endTime);
requestMap.put("sign",LiveSignUtil.getSign(requestMap, appSecret));
String response = HttpUtil.get(url, requestMap);
log.info("测试查询频道多场次概览统计数据,返回值:{}",response);
//do somethings
}
Response Example
For global error descriptions, see Global Error Description
Success Example
{
"code":200,
"status":"success",
"message":"",
"data":{
"list":[
{
"channelId":1965681,
"sessionId":"ftmnaan4l3",
"name":"Junit测试(勿删)",
"startTime":1606986241000,
"duration":174,
"liveUV":1,
"livePV":1,
"playbackPV":0,
"playbackUV":0
},
{
"channelId":1965681,
"sessionId":"fv3ma84e63",
"name":"Junit测试(勿删)",
"startTime":1611137359000,
"duration":203,
"liveUV":1,
"livePV":1,
"playbackPV":0,
"playbackUV":0
}
]
}
}
Error Example
{
"code": 400,
"status": "error",
"message": "invalid signature.",
"data": ""
}
