Polyv Help Center

Help Center

group_create_viewer_name

Updated: 2025-09-26 17:36:06

1. Adding Viewers to a Group Supports Nickname Input

Description

1、分组添加观众支持传昵称
2、接口支持https协议

Interface URL

http://api.polyv.net/live/v4/channel/lottery-viewer-list/create-viewer-name

Request Method

POST

Call Constraints

  1. The interface supports both HTTP and HTTPS. HTTPS is recommended for security. The interface has call frequency limits. For details, please refer to bzd.

  2. If parameters are incorrect, a 400 exception will be returned.

Request Parameter Description

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 saved or used directly on the client. All APIs must be called through the customer's own server to relay requests to the POLYV server and obtain response data. [See Signature Generation Rules]
channelId true String Channel ID

Request Body Parameter Description

Parameter Required Type Description
groupId true String Group ID
viewerNames true Array Array of viewer entries [See viewerNames Parameter Description]

viewerNames Parameter Description

Parameter Required Type Description
viewerId true String Viewer ID
viewerName true String Viewer nickname, allows Chinese, English, or an empty string (indicating no nickname)

Request Body JSON Parameters:

{
    "groupId": 1900,
    "viewerNames": [
        {
            "viewerId": "19",
            "viewerName": "中文"
        },
        {
            "viewerId": "190",
            "viewerName": "English"
        },
        {
            "viewerId": "1900",
            "viewerName": ""
        }
    ]
}

Example

https://api.polyv.net/live/v4/channel/lottery-viewer-list/create-viewer-name?appId=hb5u8hrdz9&channelId=6560451&timestamp=1758087275475&sign=7C409278FE170B563A3802D56734C61E

Response Parameter Description

Parameter Type Description
code Integer Response 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, not for business logic
error Object Error information when the status code is not 200 [See Error Field Description]
data Array Detailed response information [See data Field Description]

Error Response Description

Parameter Type Description
code Integer Error code, used to identify the specific error cause
desc String Error description, corresponding to error.code

data Response Description

Parameter Type Description
id Long Auto-increment record ID
groupId Integer Group ID
viewerId String Viewer ID
viewerName String Viewer nickname

Java Request Example

For quick integration of the basic code, please download the relevant dependency source code. Click here to download the source code. After downloading, add it to your own source project. The 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 for API functionality integration. The Live Java SDK provides unified encapsulation and optimization for API call logic, exception handling, data signing, and HTTP request thread pools.

private final Logger log = LoggerFactory.getLogger(getClass());

/**
 * 分组批量添加观众昵称(create-viewer-name)
 * @throws IOException
 * @throws NoSuchAlgorithmException
 */
@Test
public void groupViewerNamesAdd() throws IOException, NoSuchAlgorithmException {
    // 公共参数(请替换为你的实际值)
    String appId = super.appId;
    String appSecret = super.appSecret;
    String timestamp = String.valueOf(System.currentTimeMillis());

    // API 地址(使用 HTTPS)
    String url = "https://api.polyv.net/live/v4/channel/lottery-viewer-list/create-viewer-name";

    // 业务参数
    int channelId = 5004544;    // 频道号
    int groupId   = 1900;       // 分组ID
    // 待添加的观众
    List<Map<String, String>> viewerNames = new ArrayList<>();
    viewerNames.add(Map.of("viewerId", "19",   "viewerName", "中文"));
    viewerNames.add(Map.of("viewerId", "190",  "viewerName", "English"));
    viewerNames.add(Map.of("viewerId", "1900", "viewerName", "")); // 允许空昵称

    // http 调用逻辑
    Map<String, String> query = new HashMap<>();
    query.put("appId", appId);
    query.put("timestamp", timestamp);
    query.put("channelId", String.valueOf(channelId)); // 注意:Map<String,String> 需转字符串

    // 组装 JSON Body
    Map<String, Object> body = new HashMap<>();
    body.put("groupId", groupId);
    body.put("viewerNames", viewerNames);

    // 生成签名(大写 32 位 MD5)。通常仅包含公共参数;若签名包含 body 字段,请与服务端保持一致。
    query.put("sign", LiveSignUtil.getSign(query, appSecret));

    // 拼接带 query 的最终URL
    url = HttpUtil.appendUrl(url, query);

    // 发送 JSON(确保 Content-Type: application/json; charset=utf-8)
    String response = HttpUtil.postJsonBody(url, JSON.toJSONString(body), null);

    log.info("测试分组批量添加观众昵称,返回值:{}", response);
    // do something...
}

Response Example

For global error descriptions, see Global Error Description

Success Example

{
    "code": 200,
    "status": "success",
    "requestId": "32d9c92e-99b4-4941-ab0b-661291d57115",
    "data": [
        {
            "id": 653349,
            "groupId": 1900,
            "viewerId": "19",
            "viewerName": "中文",
            "createTime": 1758268299975
        },
        {
            "id": 653350,
            "groupId": 1900,
            "viewerId": "190",
            "viewerName": "English",
            "createTime": 1758268299975
        },
        {
            "id": 653351,
            "groupId": 1900,
            "viewerId": "1900",
            "viewerName": "",
            "createTime": 1758268299975
        }
    ],
    "success": true
}

Error Example

{
    "code": 20000,
    "status": "error",
    "error": {
        "code": 20000,
        "desc": "appId is required."
    },
    "success": false
}
联系客服,在线咨询