Paginate Chat Room Messages
Updated: 2022-05-23 14:30:29
API URL
http://api.polyv.net/live/v2/chat/{channelId}/getHistoryByPage
API Description
1、作用:查询一段时间内的聊天记录,时间格式为yyyy-MM-dd 或 yyyy-MM-dd HH:mm:ss。
如未提交具体时间,只提交了日期,开始时间默认为日期当天的 00:00:00,结束时间为日期当天的23:59:59
2、接口支持https协议
3、接口URL中的{channelId}为 频道ID
Supported Format
JSON
Request Method
POST,GET
Request Parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
| startDay | Yes | String | Start time of chat records, format: yyyy-MM-dd (e.g., 2017-08-01) or yyyy-MM-dd HH:mm:ss (e.g., 2017-08-01 16:30:12) |
| endDay | Yes | String | End time of chat records, same format requirement as above |
| appId | Yes | String | Obtained from API settings, the appId registered in the live system |
| page | No | int | Page number of chat records to retrieve, default is 1 |
| limit | No | int | Number of records per page, default is 1000 |
| timestamp | Yes | String | Current 13-digit millisecond timestamp, valid for 3 minutes |
| sign | Yes | String | Signature, 32-character uppercase MD5 value |
| userType | No | String | User type, multiple types can be selected separated by commas |
Successful Response JSON Example
{
"code": 200,
"data": {
"list": [
{
"clientIP": "",
"content": "ss",
"event": "0",
"id": "29451af0-e936-11e7-b267-81b6b5e6b627",
"image": "",
"msyType": "0",
"roomId": "110867",
"time": 1514180448799,
"user": {
"banned": false,
"clientIp": "39.155.185.29",
"nick": "游客",
"pic": "http://www.polyv.net/images/effect/effect-device.png",
"roomId": "110867",
"uid": "P-X2nETUdWGEGmEJEqL8",
"userId": "4b6c3fba-5774-4807-a34e-bb9bc306236e",
"userType": "slice"
},
"userType": "\"slice\""
},
{
"clientIP": "",
"content": "哈哈",
"event": "0",
"id": "f812f360-e94b-11e7-b267-81b6b5e6b627",
"image": "",
"msyType": "0",
"roomId": "110867",
"time": 1514189815190,
"user": {
"banned": false,
"clientIp": "",
"nick": "游客",
"pic": "http://www.polyv.net/images/effect/effect-device.png",
"roomId": "110867",
"uid": "hzx-KN4fAjBnEeumEsY1",
"userId": "1514189810254",
"userType": ""
},
"userType": ""
}
],
"page": 1,
"size": 2,
"totalCount": 6126,
"totalPage": 3063
},
"message": "",
"status": "success"
}
Failed Response JSON Examples
No appId provided
{
"code": 400,
"status": "error",
"message": "appId not found.",
"data": ""
}
Incorrect appId
{
"code": 400,
"status": "error",
"message": "application not found.",
"data": ""
}
Timestamp error
{
"code": 400,
"status": "error",
"message": "invalid timestamp.",
"data": ""
}
Signature error
{
"code": 403,
"status": "error",
"message": "invalid signature.",
"data": ""
}
Channel ID error
{
"code": 400,
"status": "error",
"message": "channel not found.",
"data": ""
}
Start time is empty
{
"code": 400,
"status": "error",
"message": "startDay can not be empty.",
"data": ""
}
End time is empty
{
"code": 400,
"status": "error",
"message": "endDay can not be empty.",
"data": ""
}
Incorrect start time format (correct format: yyyy-MM-dd)
{
"code": 400,
"status": "error",
"message": "the startDay is no right.",
"data": ""
}
Incorrect start time format (correct format: yyyy-MM-dd)
{
"code": 400,
"status": "error",
"message": "the endDay is no right.",
"data": ""
}
End time is earlier than start time
{
"code": 400,
"status": "error",
"message": "the endDay can not be earlier than the startDay.",
"data": ""
}
Other errors
{
"code": 400,
"status": "error",
"message": "无法访问聊天室数据",
"data": ""
}
Field Description
| Parameter | Description |
|---|---|
| code | Request status response code |
| status | Request status |
| message | Error message |
| clientIP | User IP |
| content | Chat content |
| id | Chat message ID |
| image | Image URL for image messages |
| roomId | Channel ID |
| time | Timestamp when the message was sent |
| clientIp | User IP |
| nick | Viewer nickname |
| pic | Viewer avatar |
| roomId | Channel ID |
| uid | Socket-assigned ID, where uid=1 indicates tip, uid=2 indicates custom message, uid=3 indicates red envelope |
| userId | Unique user identifier |
| userType | User type, currently includes teacher, assistant, manager, slice (cloud classroom student) |
| page | Current page |
| size | Data size per page |
| totalCount | Total data size |
| totalPage | Total number of pages |
PHP Request Example
<?php
//引用config.php
include 'config.php';
//接口需要的参数(非sign)赋值
$channelId = "127075";
$startDay = "2017-08-24";
$endDay = "2018-08-24";
$params = array(
'appId'=>$appId,
'startDay'=>$startDay,
'endDay'=>$endDay,
'timestamp'=>$timestamp
);
//生成sign
$sign = getSign($params); //详细查看config.php文件的getSign方法
//接口请求url
$url = "http://api.polyv.net/live/v2/chat/{channelId}/getHistoryByPage?appId=$appId×tamp=$timestamp&sign=$sign&startDay=$startDay&endDay=$endDay";
//输出接口请求结果
echo file_get_contents($url);
?>
