Polyv Help Center

Help Center

Query Video Playback Time Distribution

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

API Description

1、通过时间范围查询用户视频播放时段统计数据,播放后生成数据需间隔一到两小时,其中流量数据间隔一个自然日生成
2、接口URL中的{userid}为点播账号userid,具体参考菜单【使用须知】->【获取密钥】
3、接口支持https协议

API URL

http://api.polyv.net/v2/hourly/{userid}

Online API Call

Request Method

GET

API Constraints

  1. The API supports both HTTP and HTTPS. HTTPS is recommended for security. API calls are subject to rate limits. 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 secretkey used to generate the signature is critical for communication data security. It must never be stored on the client side. All APIs must be called through your own server to relay requests to the POLYV server for response data. See signature generation rules
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/hourly/1b448be323?sign=571A6C9924A207BF92635FE5661144844519E0F2&ptime=1617785134079&dr=last_month

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, provides error details when code is 400 or 500
data Array Returns video playback time distribution statistics on success, returns empty on failure See data field description

data Parameter Description

Field Type Description
currentHour Integer Playback hour
formatPcPlayDuration String PC playback duration, format: hours:minutes:seconds
pcPlayDuration Integer PC playback duration in seconds
pcFlowSize Long PC data consumption in bytes
pcVideoView Integer PC play count
pcUniqueViewer Integer PC unique viewers
formatMobilePlayDuration String Mobile playback duration, format: hours:minutes:seconds
mobilePlayDuration Integer Mobile playback duration in seconds
mobileFlowSize Long Mobile data consumption in bytes
mobileVideoView Integer Mobile play count
mobileUniqueViewer Integer Mobile unique viewers

Error Code List

Error 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 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
401 start and end illegal. Start date is greater than end date

Java Request Example

For quick integration of basic code, please download the relevant dependency source code. Click to download source code. After downloading, add it to your own source 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 testGetPlayTimesByPeriod() 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/hourly/%s", userId);
    String dr = "last_month";
    String start = "2021-03-31";
    String end = "2021-04-02";

    Map<String, String> requestMap = new HashMap<>();
    requestMap.put("ptime", ptime);
    requestMap.put("dr", dr);
    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": [
    {
      "currentHour": 0,
      "formatPcPlayDuration": "00:00:00",
      "pcPlayDuration": 0,
      "pcFlowSize": 0,
      "pcVideoView": 0,
      "pcUniqueViewer": 0,
      "formatMobilePlayDuration": "00:00:00",
      "mobilePlayDuration": 0,
      "mobileFlowSize": 0,
      "mobileVideoView": 0,
      "mobileUniqueViewer": 0
    },
    {
      "currentHour": 1,
      "formatPcPlayDuration": "00:00:00",
      "pcPlayDuration": 0,
      "pcFlowSize": 0,
      "pcVideoView": 0,
      "pcUniqueViewer": 0,
      "formatMobilePlayDuration": "00:00:00",
      "mobilePlayDuration": 0,
      "mobileFlowSize": 0,
      "mobileVideoView": 0,
      "mobileUniqueViewer": 0
    },
    {
      "currentHour": 2,
      "formatPcPlayDuration": "00:00:00",
      "pcPlayDuration": 0,
      "pcFlowSize": 0,
      "pcVideoView": 0,
      "pcUniqueViewer": 0,
      "formatMobilePlayDuration": "00:00:00",
      "mobilePlayDuration": 0,
      "mobileFlowSize": 0,
      "mobileVideoView": 0,
      "mobileUniqueViewer": 0
    },
    {
      "currentHour": 3,
      "formatPcPlayDuration": "00:00:00",
      "pcPlayDuration": 0,
      "pcFlowSize": 0,
      "pcVideoView": 0,
      "pcUniqueViewer": 0,
      "formatMobilePlayDuration": "00:00:00",
      "mobilePlayDuration": 0,
      "mobileFlowSize": 0,
      "mobileVideoView": 0,
      "mobileUniqueViewer": 0
    },
    {
      "currentHour": 4,
      "formatPcPlayDuration": "00:00:00",
      "pcPlayDuration": 0,
      "pcFlowSize": 0,
      "pcVideoView": 0,
      "pcUniqueViewer": 0,
      "formatMobilePlayDuration": "00:00:00",
      "mobilePlayDuration": 0,
      "mobileFlowSize": 0,
      "mobileVideoView": 0,
      "mobileUniqueViewer": 0
    },
    {
      "currentHour": 5,
      "formatPcPlayDuration": "00:00:00",
      "pcPlayDuration": 0,
      "pcFlowSize": 0,
      "pcVideoView": 0,
      "pcUniqueViewer": 0,
      "formatMobilePlayDuration": "00:00:00",
      "mobilePlayDuration": 0,
      "mobileFlowSize": 0,
      "mobileVideoView": 0,
      "mobileUniqueViewer": 0
    },
    {
      "currentHour": 6,
      "formatPcPlayDuration": "00:00:00",
      "pcPlayDuration": 0,
      "pcFlowSize": 0,
      "pcVideoView": 0,
      "pcUniqueViewer": 0,
      "formatMobilePlayDuration": "00:00:00",
      "mobilePlayDuration": 0,
      "mobileFlowSize": 0,
      "mobileVideoView": 0,
      "mobileUniqueViewer": 0
    },
    {
      "currentHour": 7,
      "formatPcPlayDuration": "00:00:00",
      "pcPlayDuration": 0,
      "pcFlowSize": 0,
      "pcVideoView": 0,
      "pcUniqueViewer": 0,
      "formatMobilePlayDuration": "00:00:00",
      "mobilePlayDuration": 0,
      "mobileFlowSize": 0,
      "mobileVideoView": 0,
      "mobileUniqueViewer": 0
    },
    {
      "currentHour": 8,
      "formatPcPlayDuration": "00:00:00",
      "pcPlayDuration": 0,
      "pcFlowSize": 0,
      "pcVideoView": 0,
      "pcUniqueViewer": 0,
      "formatMobilePlayDuration": "00:00:00",
      "mobilePlayDuration": 0,
      "mobileFlowSize": 0,
      "mobileVideoView": 0,
      "mobileUniqueViewer": 0
    },
    {
      "currentHour": 9,
      "formatPcPlayDuration": "00:00:21",
      "pcPlayDuration": 21,
      "pcFlowSize": 3627536,
      "pcVideoView": 2,
      "pcUniqueViewer": 2,
      "formatMobilePlayDuration": "00:00:00",
      "mobilePlayDuration": 0,
      "mobileFlowSize": 0,
      "mobileVideoView": 0,
      "mobileUniqueViewer": 0
    },
    {
      "currentHour": 10,
      "formatPcPlayDuration": "00:01:32",
      "pcPlayDuration": 92,
      "pcFlowSize": 43331003,
      "pcVideoView": 6,
      "pcUniqueViewer": 2,
      "formatMobilePlayDuration": "00:02:35",
      "mobilePlayDuration": 155,
      "mobileFlowSize": 33535828,
      "mobileVideoView": 3,
      "mobileUniqueViewer": 1
    },
    {
      "currentHour": 11,
      "formatPcPlayDuration": "00:03:10",
      "pcPlayDuration": 190,
      "pcFlowSize": 76230820,
      "pcVideoView": 13,
      "pcUniqueViewer": 5,
      "formatMobilePlayDuration": "00:00:40",
      "mobilePlayDuration": 40,
      "mobileFlowSize": 4046327,
      "mobileVideoView": 1,
      "mobileUniqueViewer": 1
    },
    {
      "currentHour": 12,
      "formatPcPlayDuration": "00:00:30",
      "pcPlayDuration": 30,
      "pcFlowSize": 18708078,
      "pcVideoView": 3,
      "pcUniqueViewer": 1,
      "formatMobilePlayDuration": "00:00:00",
      "mobilePlayDuration": 0,
      "mobileFlowSize": 0,
      "mobileVideoView": 0,
      "mobileUniqueViewer": 0
    },
    {
      "currentHour": 13,
      "formatPcPlayDuration": "00:00:00",
      "pcPlayDuration": 0,
      "pcFlowSize": 0,
      "pcVideoView": 0,
      "pcUniqueViewer": 0,
      "formatMobilePlayDuration": "00:00:00",
      "mobilePlayDuration": 0,
      "mobileFlowSize": 0,
      "mobileVideoView": 0,
      "mobileUniqueViewer": 0
    },
    {
      "currentHour": 14,
      "formatPcPlayDuration": "00:03:40",
      "pcPlayDuration": 220,
      "pcFlowSize": 99915723,
      "pcVideoView": 13,
      "pcUniqueViewer": 4,
      "formatMobilePlayDuration": "00:00:00",
      "mobilePlayDuration": 0,
      "mobileFlowSize": 0,
      "mobileVideoView": 0,
      "mobileUniqueViewer": 0
    },
    {
      "currentHour": 15,
      "formatPcPlayDuration": "00:02:53",
      "pcPlayDuration": 173,
      "pcFlowSize": 103330520,
      "pcVideoView": 18,
      "pcUniqueViewer": 5,
      "formatMobilePlayDuration": "00:00:37",
      "mobilePlayDuration": 37,
      "mobileFlowSize": 5371656,
      "mobileVideoView": 2,
      "mobileUniqueViewer": 2
    },
    {
      "currentHour": 16,
      "formatPcPlayDuration": "00:06:23",
      "pcPlayDuration": 383,
      "pcFlowSize": 93677801,
      "pcVideoView": 25,
      "pcUniqueViewer": 5,
      "formatMobilePlayDuration": "00:01:00",
      "mobilePlayDuration": 60,
      "mobileFlowSize": 22594584,
      "mobileVideoView": 3,
      "mobileUniqueViewer": 3
    },
    {
      "currentHour": 17,
      "formatPcPlayDuration": "00:08:08",
      "pcPlayDuration": 488,
      "pcFlowSize": 70086213,
      "pcVideoView": 8,
      "pcUniqueViewer": 5,
      "formatMobilePlayDuration": "00:04:15",
      "mobilePlayDuration": 255,
      "mobileFlowSize": 67539370,
      "mobileVideoView": 7,
      "mobileUniqueViewer": 1
    },
    {
      "currentHour": 18,
      "formatPcPlayDuration": "00:01:53",
      "pcPlayDuration": 113,
      "pcFlowSize": 34434354,
      "pcVideoView": 8,
      "pcUniqueViewer": 3,
      "formatMobilePlayDuration": "00:00:10",
      "mobilePlayDuration": 10,
      "mobileFlowSize": 1196895,
      "mobileVideoView": 1,
      "mobileUniqueViewer": 1
    },
    {
      "currentHour": 19,
      "formatPcPlayDuration": "00:00:00",
      "pcPlayDuration": 0,
      "pcFlowSize": 0,
      "pcVideoView": 0,
      "pcUniqueViewer": 0,
      "formatMobilePlayDuration": "00:00:00",
      "mobilePlayDuration": 0,
      "mobileFlowSize": 0,
      "mobileVideoView": 0,
      "mobileUniqueViewer": 0
    },
    {
      "currentHour": 20,
      "formatPcPlayDuration": "00:00:00",
      "pcPlayDuration": 0,
      "pcFlowSize": 0,
      "pcVideoView": 0,
      "pcUniqueViewer": 0,
      "formatMobilePlayDuration": "00:00:00",
      "mobilePlayDuration": 0,
      "mobileFlowSize": 0,
      "mobileVideoView": 0,
      "mobileUniqueViewer": 0
    },
    {
      "currentHour": 21,
      "formatPcPlayDuration": "00:00:00",
      "pcPlayDuration": 0,
      "pcFlowSize": 0,
      "pcVideoView": 0,
      "pcUniqueViewer": 0,
      "formatMobilePlayDuration": "00:00:00",
      "mobilePlayDuration": 0,
      "mobileFlowSize": 0,
      "mobileVideoView": 0,
      "mobileUniqueViewer": 0
    },
    {
      "currentHour": 22,
      "formatPcPlayDuration": "00:00:00",
      "pcPlayDuration": 0,
      "pcFlowSize": 0,
      "pcVideoView": 0,
      "pcUniqueViewer": 0,
      "formatMobilePlayDuration": "00:00:00",
      "mobilePlayDuration": 0,
      "mobileFlowSize": 0,
      "mobileVideoView": 0,
      "mobileUniqueViewer": 0
    },
    {
      "currentHour": 23,
      "formatPcPlayDuration": "00:00:00",
      "pcPlayDuration": 0,
      "pcFlowSize": 0,
      "pcVideoView": 0,
      "pcUniqueViewer": 0,
      "formatMobilePlayDuration": "00:00:00",
      "mobilePlayDuration": 0,
      "mobileFlowSize": 0,
      "mobileVideoView": 0,
      "mobileUniqueViewer": 0
    }
  ]
}

Error Example

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