Polyv Help Center

Help Center

Set Player Pre-Roll Ad

Updated: 2023-11-14 14:07:19

Interface Description

1、接口用于设置某频道播放器的片头广告
2、接口URL中的{channelId}为 频道ID
3、接口支持https

Interface URL

http://api.polyv.net/live/v2/channelAdvert/{channelId}/updateHead

Request Method

POST

Supported Format

JSON

Request Limit

TRUE

Request Parameters

Parameter Required Type Description
appId Yes string Obtained from API settings, the appId registered in the live streaming system
timestamp Yes string Current 13-digit millisecond timestamp, valid for 3 minutes
sign Yes string Signature, 32-character uppercase MD5 value
enabled No string Y-Enable, N-Disable; when setting the switch, other configuration parameters are invalid
headAdvertType No string Ad type, NONE-No ad, IMAGE-Image ad, FLV-Video ad
headAdvertMediaUrl No string Ad media URL
headAdvertHref No string Ad click-through URL
headAdvertDuration No int Ad duration
headAdvertWidth No int Ad width
headAdvertHeight No int Ad height

Successful Response JSON Example:

{
    "code": 200,
    "status": "success",
    "message": "",
    "data": true
}

Failed Response JSON Examples:

No appId provided

{
    "code": 400,
    "status": "error",
    "message": "appId is required.",
    "data": ""
}

Incorrect appId

{
    "code": 400,
    "status": "error",
    "message": "application not found.",
    "data": ""
}

Invalid timestamp

{
    "code": 400,
    "status": "error",
    "message": "invalid timestamp.",
    "data": ""
}

Invalid signature

{
    "code": 403,
    "status": "error",
    "message": "invalid signature.",
    "data": ""
}

Channel does not exist

{
    "code": 400,
    "status": "error",
    "message": "channel not found.",
    "data": ""
}

Incorrect channel type

{
    "code": 400,
    "status": "error",
    "message": "invalid advert type",
    "data": ""
}

Invalid switch parameter

{
    "code": 400,
    "status": "error",
    "message": "invalid enabled value",
    "data": ""
}

Illegal request

{
    "code": 403, 
    "status": "error", 
    "message": "operation forbidden.", 
    "data": ""
}

Field Description

Parameter Description
code Request result code, 200 for success, 400 for error, 403 for signature error
status Request result, "success" for success, "error" for error
message Error message, empty string on success, error message on failure
data True on success, empty string on error

PHP Request Example

<?php
//引用config.php
include 'config.php';

//接口需要的参数(非sign)赋值
$channelId="123713";

$headAdvertType = "none";
$headAdvertMediaUrl = "http://www.headAdvertMediaUrl.com";
$headAdvertHref = "http://www.headAdvertHref.com";
$headAdvertDuration = 50;
$headAdvertWidth = 100;
$headAdvertHeight = 200;

$params = array(
    'appId' => $appId,
    'timestamp' => $timestamp,
    'headAdvertType' => $headAdvertType,
    'headAdvertMediaUrl' => $headAdvertMediaUrl,
    'headAdvertHref' => $headAdvertHref,
    'headAdvertDuration' => $headAdvertDuration,
    'headAdvertWidth' => $headAdvertWidth,
    'headAdvertHeight' => $headAdvertHeight
  );

//生成sign
$sign = getSign($params); //详细查看config.php文件的getSign方法


$url="http://api.polyv.net/live/v2/channelAdvert/".$channelId."/updateHead";

function post($url, $post_data = '', $timeout = 5){
   $ch = curl_init();
   curl_setopt ($ch, CURLOPT_URL, $url);
   curl_setopt ($ch, CURLOPT_POST, 1);
   if($post_data != ''){
      curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
   }

   curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
   curl_setopt($ch, CURLOPT_HEADER, false);
   $file_contents = curl_exec($ch);
   curl_close($ch);
   return $file_contents;
}

$params["sign"] = $sign;
echo post($url, $params);
?>

Signature Rules (See config.php file code)

Signature Generation Rules

联系客服,在线咨询
在线咨询