Polyv Help Center

Help Center

Query Channel Chat History

Updated: 2024-12-11 15:24:57

API Description

1、通过频道号,查询一段时间内的聊天记录
2、接口支持https协议

API URL

http://api.polyv.net/live/v3/channel/chat/get-history-page

Online API Call

Request Method

GET

API Constraints

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

  2. Time format is yyyy-MM-dd or yyyy-MM-dd HH:mm:ss. If only a date is provided without a specific time, the start time defaults to 00:00:00 and the end time to 23:59:59 of that date.

Request Parameters

Parameter Required Type Description
appId true String Account appId See Get 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 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
startDay true String Start time of chat records
Format: yyyy-MM-dd, e.g., 2021-03-01
Or yyyy-MM-dd HH:mm:ss, e.g., 2021-03-01 16:30:12
endDay true String End time of chat records, same format as above
channelId true String Channel ID
page false Integer Page number for chat records, defaults to 1
pageSize false Integer Records per page, defaults to 1000, maximum 1000. Values greater than 1000 will not return contents data
userType false String User types, multiple types separated by commas
slice: Cloud classroom student
teacher: Instructor
guest: Guest
manager: Administrator
assistant: Teaching assistant
viewer: Special audience
monitor: Event monitor
attendee: Seminar participant
student: General live stream viewer
status false String Chat record review status, defaults to pass: Approved
pass: Approved
censor: Under review and deleted
source false String Type, defaults to public chat if not specified
extend: Administrator private chat
roomId false String Room ID if available, defaults to not passed
hasTotal false String Whether to return the total count for the query. Y: Yes, N: No, defaults to N.
Note: This parameter may affect API response performance. It is recommended not to pass this parameter unless strongly needed. You can determine if there is a next page based on the length of the contents array in the response.

Example

http://api.polyv.net/live/v3/channel/chat/get-history-page?startDay=2020-03-10&appId=frlr1z1zn3&endDay=2021-03-10&sign=FD60256504E55BC4986B1BF9D207A997&pageSize=20&page=1&userType=&source=&channelId=1965681&roomId=&timestamp=1635478961187&status=

Response Parameters

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, assists in describing error reasons when code is 400 or 500
data Array Chat information array See data field description

data Field Description

Parameter Type Description
pageSize Integer Data size per page
pageNumber Integer Current page number
totalItems Integer Total number of items. Only has a value when hasTotal is Y, otherwise always 0.
totalPages Integer Total pages, same constraint as above
contents Object Query result list See Contents parameter description

contents Field Description

Parameter Type Description
id String Chat message ID
accountId String Account ID
clientIP String User IP (for data security, this field will no longer be returned)
content String Chat content. When the message is an image type, content is a JSON string (explained below)
event String Event, refer to the chat room SDK for details
image String Image URL for image messages
msgType String Message type
redpaper: Red packet message
chatImg: Image message
custom: Custom message (sent via socket)
reward: Tip message
customerMessage: Custom message (sent via HTTP API)
Empty: General chat message
quote String Quote
sessionId String Session ID
roomId String Room ID
channelId String Channel ID
time Long Timestamp when the message was sent
userType String User type
slice: Cloud classroom student
teacher: Instructor
guest: Guest
manager: Administrator
assistant: Teaching assistant
viewer: Special audience
monitor: Event monitor
attendee: Seminar participant
student: General live stream viewer
status String Review status
pass: Approved
censor: Under review
delete: Deleted
sourceType String Message source
public: Group chat
extend: Administrator private chat
user Object Chat information array See user field description

Description When content is in JSON Format

Distinguish message types based on msgType
When msgType is redpaper, it indicates a red packet:
Parameter Type Description
content String Red packet name
msgSource String Message type
number Number Number of red packets
redCacheId String Cached red packet ID
redpackId String Red packet ID
totalAmount String Total red packet amount
type String Red packet type: normal for regular, rain for red packet rain, password for password red packet, official_normal for broadcast-end regular red packet
When msgType is reward, it indicates a tip:
Parameter Type Description
userId String User ID
goodNum Number Number of tipped gifts
unick String User nickname
gimg String Gift image URL
rewardContent String Tip content
uimg String User avatar
rewardUser Object Tipper See rewardUser field description
When msgType is chatImg, it indicates an image:
Parameter Type Description
id String Image ID
msgSource String Message type
status String Image upload status: upLoadingSuccess indicates successful upload
uploadImgUrl String URL after successful upload, multiple URLs separated by commas
size Object Image dimensions: width for width, height for height
When msgType is custom, it indicates a custom message:
Parameter Type Description
msgSource String Message type
EVENT String Custom message event type
version String Custom message version
emitMode Number Custom message broadcast mode
tip Number Custom message prompt
data Object Custom message body

user Field Description

Parameter Type Description
actor String Role
banned Boolean Whether muted
channelId String Channel ID
clientIp String User IP
nickname String Viewer nickname
pic String Viewer avatar
roomId String Room ID
sessionId String Session ID
uid String Socket ID
userId String Unique user identifier
userSource String Viewer source
userType String User type
slice: Cloud classroom student
teacher: Instructor
guest: Guest
manager: Administrator
assistant: Teaching assistant
viewer: Special audience
monitor: Event monitor
attendee: Seminar participant
student: General live stream viewer
param4 String Custom user field
param5 String Custom user field

rewardUser Field Description

Parameter Type Description
deviceType String Device type
nick String Viewer nickname
uid String Socket ID
clientIp String User IP
banned Boolean Whether muted
pic String User avatar
userType String User type
slice: Cloud classroom student
teacher: Instructor
guest: Guest
manager: Administrator
assistant: Teaching assistant
viewer: Special audience
monitor: Event monitor
attendee: Seminar participant
student: General live stream viewer
customize Number Whether it is a custom gift: 0 for no, 1 for yes
userId String User ID
channelId String Channel ID
roomId String Room ID
scene String Scene
alone: Event live stream
ppt: Three-panel screen
topclass: Large class

Java Request Example

For quick integration of basic code, 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(ChatMessageTest.class);

    /**
     * 查询频道聊天记录
     * @throws IOException
     */
    @Test
    public void testGetMessageList() throws IOException, NoSuchAlgorithmException {
        //公共参数,填写自己的实际参数
        String appId = super.appId;
        String appSecret = super.appSecret;
        String timestamp = String.valueOf(System.currentTimeMillis());
        
        //业务参数
        String url = "http://api.polyv.net/live/v3/channel/chat/get-history-page";
        String startDay = "2020-03-10";
        String endDay = "2021-03-10";
        String channelId = "1965681";
        Integer page = 1;
        Integer pageSize = 20;
        String userType = "";
        String status = "";
        String source = "";
        String roomId = "";
        
        //http 调用逻辑
        Map<String,String> requestMap = new HashMap<>();
        requestMap.put("appId", appId);
        requestMap.put("timestamp",timestamp);
        requestMap.put("startDay",startDay);
        requestMap.put("endDay",endDay);
        requestMap.put("channelId",channelId);
        requestMap.put("page",page.toString());
        requestMap.put("pageSize",pageSize.toString());
        requestMap.put("userType",userType);
        requestMap.put("status",status);
        requestMap.put("source",source);
        requestMap.put("roomId",roomId);
        requestMap.put("sign", LiveSignUtil.getSign(requestMap, appSecret));
        String response = HttpUtil.get(url, requestMap);
        log.info("测试查询频道聊天记录接口返回值:{}",response);
    }

Response Example

For global error descriptions, see Global Error Description

Success Example

{
    "code": 200,
    "status": "success",
    "message": "",
    "data": {
        "pageNumber": 1,
        "pageSize": 20,
        "totalPages": 0,
        "totalItems": 0,
        "contents": [
            {
                "id": "874e2850-12bc-11eb-963f-578bb7bc5db5",
                "accountId": "",
                "clientIP": "",
                "content": "hello 大家好",
                "event": null,
                "image": "",
                "msgType": null,
                "quote": null,
                "sessionId": "fs9v9y4nxf",
                "roomId": "1965681",
                "channelId": 1965681,
                "time": 1603188649810,
                "userType": "",
                "status": "",
                "sourceType": "public",
                "user": {
                    "actor": null,
                    "banned": false,
                    "channelId": 1965681,
                    "clientIp": "",
                    "nickname": "thomas",
                    "pic": "http://s1.videocc.net/default-img/avatar/teacher.png",
                    "roomId": "1965681",
                    "sessionId": null,
                    "uid": "",
                    "userId": "1965681_reboot_0",
                    "userSource": null,
                    "userType": ""
                }
            }
        ]
    }
}

Error Example

{
    "code": 400,
    "status": "error",
    "message": "invalid signature.",
    "data": ""
}
联系客服,在线咨询