Create Advertisement
Updated: 2025-01-14 16:12:03
API Description
1、通过分类id为分类下的所有视频创建广告
2、接口URL中的{userid}为点播账号userid,具体参考菜单【使用须知】->【获取密钥】
3、接口支持https协议
API URL
http://api.polyv.net/v2/advertising/{userid}/create
Request Method
POST
API Constraints
- The API supports both HTTP and HTTPS. HTTPS is recommended for security. API calls have frequency limits. See details
Request Parameter Description
| Parameter | Required | Type | Description |
|---|---|---|---|
| ptime | true | Long | Current time in milliseconds timestamp, 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. It must not be stored or used directly on the client. 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 |
| startDate | true | String | Advertisement start date, format: yyyy-MM-dd, e.g., 2021-04-07 |
| endDate | true | String | Advertisement end date, format: yyyy-MM-dd, e.g., 2021-04-10 |
| title | true | String | Advertisement title |
| file | true | File | Advertisement material Pre-roll and post-roll ads support: JPEG, GIF, PNG, FLV, MP4 Pause ads support: SWF, PNG, JPEG, GIF Popup ads support: PNG, JPEG, GIF |
| size | false | Integer | Advertisement duration, required for all ad types except when the location parameter is pause ad. Unit: seconds |
| cataids | false | String | Category IDs, multiple IDs separated by commas. Default value is 1 (default category) |
| location | false | Integer | Advertisement type, default is pre-roll 1: Pre-roll 2: Pause 3: Post-roll 4: Popup |
| popLocation | false | Integer | Popup ad position, required when location is popup 1: Bottom right 2: Top right 3: Bottom left 4: Top left |
| popUpTime | false | Integer | Time when the popup appears, in seconds. Required when location is popup |
| status | false | Integer | Advertisement status, default is online 10: Online 1: Pending online 0: Offline |
| upTime | false | String | Advertisement start time, format: HH:mm:ss, default: 00:00:00 |
| offTime | false | String | Advertisement end time, format: HH:mm:ss, default: 23:59:59 |
| note | false | String | Advertisement description |
| skipAd | false | String | Whether to enable skip ad. Only valid when location is pre-roll. Default is N Y: Enable N: Disable |
| skipOffset | false | String | Seconds after which skipping is allowed. Required when skipAd is Y |
| skipButtonLabel | false | String | Skip button label description, default is "Skip" |
Example
http://api.polyv.net/v2/advertising/1b448be323/create
Form Parameters:
note=测试广告的描述内容&endDate=2021-4-8&popLocation=1&sign=AD41245052F42EF9D1FE41FA413948AFB60EAFCF&title=接口测试接口广告&skipAd=Y&upTime=09:45:00&cataids=1615286323771&popUpTime=2&skipButtonLabel=跳过&size=4&location=1&offTime=09:50:00&skipOffset=3&ptime=1617759804786&startDate=2021-4-7&status=10
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 message, provides error reason when code is 400 or 500 |
| data | String | Returns the advertisement ID on success, returns empty on failure |
Error Code List
| Response Code | message | Description |
|---|---|---|
| 400 | sign can not be empty. | Signature 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 string is incorrect |
| 400 | file is empty. | No file uploaded or file is empty |
| 400 | illegal file type. | Illegal file type |
| 400 | upload file failed. | File upload failed |
| 400 | startDate or endDate error. | Date format is incorrect or start date is greater than end date |
| 400 | upTime or offTime error. | Time format is incorrect or start time is greater than end time |
| 400 | param status can not be empty. | Advertisement status cannot be empty |
| 400 | title can not be empty. | Advertisement title cannot be empty |
| 400 | cataids length is not right. | Category count is incorrect |
| 400 | exist the same cataid. | Duplicate cataid exists |
| 400 | cataid type error. | cataid type error |
| 400 | cata not exist. | Category does not exist |
| 400 | cata conflict. | Cannot have both parent and child categories simultaneously |
| 400 | param location error. | Advertisement type error |
| 400 | param addrurl error. | URL address error |
| 400 | pop location error. | Popup position error |
| 400 | pop up time error. | Popup appearance time error |
| 400 | illegal skipOffset. | Skip ad is enabled but skipOffset parameter is incorrect (must not be less than 0 or greater than ad duration) |
| 400 | location type not supported to skipAd. | Advertisement type does not support enabling skip ad |
| 400 | save fail. | Server exception caused failure |
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 code project. The HttpUtil.java and VodSignUtil.java in the test cases are included in the downloaded file.
It is strongly recommended to use the VOD Java SDK for API integration. The VOD Java SDK provides a unified encapsulation and optimization for API call logic, exception handling, data signing, and HTTP request thread pools.
private static final Logger log = LoggerFactory.getLogger(VodVideoAdvertising.class);
/**
* 创建广告
*/
@Test
public void testAddAdvertising() throws Exception, NoSuchAlgorithmException {
//公共参数,填写自己的实际参数
String secretKey = super.secretKey;
String userid = super.userId;
String ptime = String.valueOf(System.currentTimeMillis());
//业务参数
String url = String.format("http://api.polyv.net/v2/advertising/%s/create", userid);
String startDate = "2021-4-7";
String endDate = "2021-4-8";
String title = "接口测试接口广告";
String advertisingPath = getClass().getResource("/file/").getPath() + "advertisement.jpeg";
File file = new File(advertisingPath);
String size = "4";
String cataids = "1615286323771";
String location = "1";
String popLocation = "1";
String popUpTime = "2";
String status = "10";
String upTime = "09:45:00";
String offTime = "09:50:00";
String note = "测试广告的描述内容";
String skipAd = "Y";
String skipOffset = "3";
String skipButtonLabel = "跳过";
Map<String, String> requestMap = new HashMap<>();
requestMap.put("ptime", ptime);
requestMap.put("startDate", startDate);
requestMap.put("endDate", endDate);
requestMap.put("title", title);
Map<String,File> fileMap = new HashMap<>();
fileMap.put("file",file);
requestMap.put("size", size);
requestMap.put("cataids", cataids);
requestMap.put("location", location);
requestMap.put("popLocation", popLocation);
requestMap.put("popUpTime", popUpTime);
requestMap.put("status", status);
requestMap.put("upTime", upTime);
requestMap.put("offTime", offTime);
requestMap.put("note", note);
requestMap.put("skipAd", skipAd);
requestMap.put("skipOffset", skipOffset);
requestMap.put("skipButtonLabel", skipButtonLabel);
requestMap.put("sign", VodSignUtil.getSign(requestMap, secretKey));
String response = HttpUtil.postFile(url, requestMap,fileMap,Constant.UTF8);
log.debug("测试创建广告,{}", response);
//do somethings
}
Response Example
For system-wide global error descriptions, see Global Error Description
Success Example
{
"code": 200,
"status": "success",
"message": "success",
"data": "f48271dff47e4ab2a414"
}
Error Example
{
"code": 400,
"status": "error",
"message": "ptime is too old.",
"data": ""
}
