Polyv Help Center

Help Center

Query Playback Traffic Statistics

Updated: 2025-01-14 16:17:27

API Description

1、通过视频id和时间范围查询单个视频播放的流量,流量数据需要间隔一个自然日生成
2、自2018年7月10日起,才可以统计到单个视频的移动端流量数据,在此之前没有移动端流量数据
3、接口URL中的{userid}为点播账号userid,具体参考菜单【使用须知】->【获取密钥】
4、接口URL中的{vid}为视频id
5、接口支持https协议

API URL

http://api.polyv.net/v2/traffic/{userid}/video/{vid}

Online API Call

Request Method

GET

API Constraints

  1. The API supports both HTTP and HTTPS. HTTPS is recommended to ensure interface security. API calls have a frequency limit. See details

  2. The request parameters start (start date) and end (end date) must be passed together. Passing only one parameter will not take effect.

  3. If both dr (time period) and start/end are passed, only start and end are valid. If none are passed, dr defaults to 7days.

Request Parameter Description

Parameter Required Type Description
ptime true Long Current time in milliseconds timestamp, valid for 3 minutes
sign true String Signature, a 40-character uppercase SHA1 value. The secret key used to generate the signature is critical for communication data security. It must never be saved or 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
dr false String Time period, default value is 7days (last 7 days)
today: Today
yesterday: Yesterday
this_week: This week
last_week: Last week
7days: Last 7 days
this_month: This month
last_month: Last month
this_year: This year
last_year: Last year
start false String Start date, format: yyyy-MM-dd, e.g., 2021-03-31
end false String End date, format: yyyy-MM-dd, e.g., 2021-04-02

Example

http://api.polyv.net/v2/traffic/1b448be323/video/1b448be323b8d9b9489dcd7e8e09f087_1?start=2021-03-31&sign=8CF133844DEA09323E8A02209F4FC438DE72450F&end=2021-04-02&ptime=1617778937390

Response Parameter Description

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. When code is 400 or 500, provides auxiliary error reason
data Array On success, returns video playback traffic statistics data. On failure, returns empty. See data field description

Data Parameter Description

Field Type Description
currentDay String Data generation date, format: yyyy-MM-dd
pcFlowSize Long PC traffic consumed, in bytes
mobileFlowSize Long Mobile traffic consumed, in bytes
totalFlowSize Long Total traffic consumed, in bytes

Error Code List

Error Code Message Description
400 sign can not be empty. Encryption string is empty
400 vid invalid. Invalid video ID
400 ptime is too old. Timestamp expired
400 ptime is illegal. Invalid timestamp format 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. Incorrect encryption string
401 start and end illegal. Start date is greater than end date

Java Request Example

For quick integration, download the relevant dependency source code. Click to download source code. After downloading, add it to your own 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 pooling.

private static final Logger log = LoggerFactory.getLogger(VodStatisticsTest.class);
/**
 * 查询播放流量统计
 * @throws Exception
 * @throws NoSuchAlgorithmException
 */
@Test
public void testGetFlowUsage() throws Exception, NoSuchAlgorithmException {
    //公共参数,填写自己的实际参数
    String secretKey = super.secretKey;
    String userId = super.userId;
    String ptime = String.valueOf(System.currentTimeMillis());
    //业务参数
    String vid = "1b448be323b8d9b9489dcd7e8e09f087_1";
    String dr = "last_month";
    String start = "2021-03-31";
    String end = "2021-04-02";
    String url = String.format("http://api.polyv.net/v2/traffic/%s/video/%s", userId,vid);

    Map<String, String> requestMap = new HashMap<>();
    requestMap.put("ptime", ptime);
    requestMap.put("start", start);
    requestMap.put("end", end);
    requestMap.put("sign", VodSignUtil.getSign(requestMap, secretKey));

    String response = HttpUtil.get(url, requestMap);
    log.debug("测试查询播放流量统计,{}", response);
    //do somethings

}

Response Example

For global error descriptions, see Global Error Description

Success Example

{
  "code": 200,
  "status": "success",
  "message": "success",
  "data": [
    {
      "currentDay": "2021-03-31",
      "pcFlowSize": 19040655,
      "mobileFlowSize": 0,
      "totalFlowSize": 19040655
    },
    {
      "currentDay": "2021-04-01",
      "pcFlowSize": 0,
      "mobileFlowSize": 0,
      "totalFlowSize": 0
    },
    {
      "currentDay": "2021-04-02",
      "pcFlowSize": 0,
      "mobileFlowSize": 0,
      "totalFlowSize": 0
    }
  ]
}

Error Example

{
  "code": 400,
  "status": "error",
  "message": "ptime is too old.",
  "data": ""
}
联系客服,在线咨询