Create a Single Danmaku
API Description
1、通过视频id创建弹幕信息,弹幕暂不支持特殊字符与表情符号
2、接口URL中的{userid}为点播账号userid,具体参考菜单【使用须知】->【获取密钥】
3、接口支持https协议
API URL
http://api.polyv.net/v2/danmu/{userid}/add
<a href="/req.html?api=http://api.polyv.net/v2/danmu/{userid}/add"" target="_blank">Online API Call
Request Method
POST
API Constraints
- The API supports both HTTP and HTTPS. HTTPS is recommended to ensure interface security. API calls have frequency limits. See details
Request Parameter Description
| Parameter | Required | Type | Description |
|---|---|---|---|
| ptime | true | Long | Current time in milliseconds, valid within 3 minutes |
| sign | true | String | Signature, a 40-character uppercase SHA1 value. The secretkey used to generate the signature is critical for communication data security and must never be used directly on the client side. All APIs must be called through the customer's own server to relay requests to the POLYV server for response data. See signature generation rules |
| vid | true | String | Video ID |
| msg | true | String | Danmaku message |
| time | true | String | Time when the danmaku appears, format: HH:mm:ss, e.g., 00:00:20 |
| sessionId | false | String | Session ID, custom parameter, e.g., student ID representing student information |
| param2 | false | String | Custom parameter |
| fontSize | false | Integer | Font size, default: 18 |
| fontMode | false | String | Display position, default: roll roll: scrolling top: top bottom: bottom |
| fontColor | false | String | Font color, format: 0xFFFFFF, default: 0xFFFFFF (white) |
Example
http://api.polyv.net/v2/danmu/1b448be323/add
Form parameters:
vid=1b448be323b68b2999802799a98dba54_1&msg=测试添加弹幕~&sign=49BBCBC672DF778CE6C6DE8EB1F4BB7BE9B2C395&time=00:00:05&ptime=1617173648080
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, when code is 400 or 500, provides additional error details |
| data | Object | Returns danmaku ID on success, empty on failure See data field description |
Data Field Description
| Parameter | Type | Description |
|---|---|---|
| Id | Integer | Danmaku ID |
Error Code List
| Error Code | Message | Description |
|---|---|---|
| 400 | sign can not be empty. | Encryption string is empty |
| 400 | ptime is too old. | Timestamp has expired |
| 400 | ptime is illegal. | Timestamp parameter format is incorrect or exceeds current time by 3 minutes |
| 400 | Could not find user by userId. | User ID does not exist |
| 400 | the sign is not right. | Signature is incorrect |
| 400 | vid doesn't exist. | Video ID is empty |
| 400 | vid, msg and time should not be empty. | Required parameters are empty |
| 400 | Wrong time format. | Danmaku time format is incorrect |
| 400 | font size illegal | Font format is invalid |
Java Request Example
For quick integration, please download the relevant dependency source code. Click here to download the source code. After downloading, add it to your own source code project. The test cases include HttpUtil.java and VodSignUtil.java in the downloaded file.
It is strongly recommended to use the VOD Java SDK for API integration. The VOD 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(VodVideoManagementTest.class);
/**
* 创建弹幕
*/
@Test
public void testAddDanmu() throws Exception, NoSuchAlgorithmException {
//公共参数,填写自己的实际参数
String secretKey = super.secretKey;
String userId = super.userId;
String ptime = String.valueOf(System.currentTimeMillis());
//业务参数
String url = "http://api.polyv.net/v2/danmu/"+userId+"/add";
String vid = "1b448be323b68b2999802799a98dba54_1";
String msg = "测试添加弹幕";
String time = "00:00:05";
Map<String, String> requestMap = new HashMap<>();
requestMap.put("ptime", ptime);
requestMap.put("vid", vid);
requestMap.put("msg", msg);
requestMap.put("time", time);
requestMap.put("sign", VodSignUtil.getSign(requestMap, secretKey));
String response = HttpUtil.postFormBody(url, requestMap);
log.debug("测试创建弹幕,{}", response);
//do somethings
}
Response Example
For global system error descriptions, see Global Error Description
Success Example
{
"code": 200,
"status": "success",
"message": "success",
"data": {
"Id": 17251132
}
}
Error Example
Timestamp expired:
{
"code": 400,
"status": "error",
"message": "ptime is too old.",
"data": ""
}
Signature error:
{
"code": 400,
"status": "error",
"message": "the sign is not right.",
"data": ""
}
Required parameter empty:
{
"code": 400,
"status": "error",
"message": "vid, msg and time should not be empty.",
"data": ""
}
Danmaku time format incorrect:
{
"code": 400,
"status": "error",
"message": "Wrong time format.",
"data": ""
}
Invalid parameter:
{
"code": 400,
"status": "error",
"message": "font size illegal",
"data": ""
}
Video does not exist:
{
"code": 400,
"status": "error",
"message": "vid doesn't exist.",
"data": ""
}
