Polyv Help Center

Help Center

Query Live Session Data Within a Time Range

Updated: 2023-03-08 11:13:29

API Description

1、查询时间内直播场次数据
2、(timestamp, appId)参与sign签名,并和sign一起通过url传递
3、接口支持https协议

API URL

http://api.polyv.net/live/v4/statistics/session-stats/list

Online API Call

Request Method

POST

API Constraints

  1. The API supports both HTTP and HTTPS. HTTPS is recommended to ensure security. API calls have frequency limits. See details

  2. If the query time range is not specified, the default query is for session report data generated between the current time and one hour prior. The maximum query time range is 24 hours.

  3. Data query range: startTime <= Live session start time, Live session end time <= endTime

  4. Data for ongoing live sessions will not be returned.

Request Parameter Description

Parameter Required Type Description
appId true String Account appId See details for obtaining secret key
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 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 to obtain response data. See signature generation rules
startTime false Long Start time, 13-digit timestamp
endTime false Long End time, 13-digit timestamp
pageNumber false Integer Current page number
pageSize false Integer Number of items per page, default is 10, maximum cannot exceed 1000

Example

http://api.polyv.net/live/v4/statistics/session-stats/list?pageNumber=1&appId=frlr1zazn3&sign=EE807FB4A859A23E5B2EFA6CFC1FE7FC&pageSize=10&startTime=1634517072111&endTime=1634599872222&timestamp=1634788009047

Response Parameter Description

Parameter Type Description
code Integer Status code, same as HTTP status code, used to determine the basic response status
status String Response result, determined by the business. Returns success on success, error on failure
success Boolean Whether the response was successful
requestId String Request ID, a unique UUID generated for each request. Only used for troubleshooting and debugging, should not be tied to business logic
error Object Error information when status code is not 200 See Error field description
data Object See data field description

Error Parameter Description

Parameter Type Description
code Integer Error code, used to determine the specific error reason
desc String Error description, corresponds to error.code

data Parameter Description

Parameter Type Description
pageNumber Integer Current page number
pageSize Integer Number of items per page
totalPages Long Total number of pages
totalItems Long Total number of items
contents Array Content of the current page See contents field description

contents Parameter Description

Parameter Type Description
channelId Integer Channel ID
sessionId String Live session ID
name String Session name
startTime Long Live start time, 13-digit timestamp
endTime Long Live end time, 13-digit timestamp
userId String Live account ID

Java Request Example

For quick integration of basic code, please download the relevant dependency source code. Click here to download the source code. After downloading, add it to your own source code project. HttpUtil.java and LiveSignUtil.java in the test cases are included in the downloaded file.

It is strongly recommended to use the Live Java SDK to implement API functionality. 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(getClass());
/**
 * 获取时间内直播场次数据
 * @throws IOException
 * @throws NoSuchAlgorithmException
 */
@Test
public void testGetLiveSession() throws IOException, NoSuchAlgorithmException {
    //公共参数,填写自己的实际参数
    String appId = super.appId;
    String appSecret = super.appSecret;
    String timestamp = String.valueOf(System.currentTimeMillis());
    
    //业务参数
    String url = "http://api.polyv.net/live/v4/statistics/session-stats/list";
    String startTime = "1634517072111";
    String endTime = "1634599872222";
    String pageNumber = "1";
    String pageSize = "10";
    
    //http 调用逻辑
    Map<String, String> requestMap = new HashMap<>();
    requestMap.put("appId", appId);
    requestMap.put("timestamp", timestamp);
    requestMap.put("startTime", startTime);
    requestMap.put("endTime", endTime);
    requestMap.put("pageNumber", pageNumber);
    requestMap.put("pageSize", pageSize);
    requestMap.put("sign", LiveSignUtil.getSign(requestMap, appSecret));
    
    url = HttpUtil.appendUrl(url, requestMap);
    String response = HttpUtil.postFormBody(url, null);
    log.info("测试获取时间内直播场次数据成功:{}", response);
    //do somethings
    
}

Response Example

For global system error descriptions, see Global Error Description

Success Example

{
    "code": 200,
    "status": "success",
    "requestId": "b38bdd97dc404213a2436e7a086b9db9.80.16347880125725671",
    "data": {
        "pageNumber": 1,
        "pageSize": 10,
        "totalPages": 1,
        "totalItems": 2,
        "contents": [
            {
                "channelId": 2272655,
                "sessionId": "g3e0fasiw0",
                "name": "JAVA大师无延迟直播课-纯视频",
                "startTime": 1634520672000,
                "endTime": 1634520742000,
                "userId": "1b448be323"
            },
            {
                "channelId": 2477096,
                "sessionId": "g3eb7xbpn4",
                "name": "JAVA 知识精讲(误删)",
                "startTime": 1634544160000,
                "endTime": 1634544232000,
                "userId": "1b448be323"
            }
        ]
    },
    "success": true
}

Error Example

{
    "code": 400,
    "status": "error",
    "requestId": "d310b70bc329403f87f77f9203d50f89.128.16360831552223589",
    "error": {
        "code": 20001,
        "desc": "application not found."
    },
    "success": false
}
联系客服,在线咨询