Polyv Help Center

Help Center

Query Terminal Environment Distribution for Video Playback

Updated: 2025-01-14 16:19:48

API Description

1、查询视频终端环境统计数据,包括浏览器环境,操作系统环境,终端环境。从播放行为产生到数据可查询的间隔时间为1~2小时
2、接口URL中的{userid}为点播账号userid,具体参考【获取密钥】
3、接口支持https协议

API URL

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

Online API Call

Request Method

GET

API Constraints

  1. The API supports both HTTP and HTTPS. HTTPS is recommended for security. API calls have frequency limits. See details

  2. The request parameters start (start date) and end (end date) must be provided together; providing only one parameter is invalid.

  3. If dr (time period) is provided together with start and end, only start and end are effective. If none are provided, dr defaults to 7days.

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. It must not be stored or used directly on the client side. All APIs must obtain response data from the POLYV server through the customer's own server relay. See signature generation rules
dr false String Time period. Default value is 7days. Possible values:
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-04-07
end false String End date, format: yyyy-MM-dd, e.g., 2021-04-10

Example

http://api.polyv.net/v2/device/1b448be323?start=2021-03-16&sign=F3A24F3621CE3D0B0B5366E56D95A6E3CF34B2AA&end=2021-03-24&ptime=1617875576619&dr=this_year

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 Object Returns domain statistics on success [See Data field description](/vod/api/statistics/get_device_stat.md?id=polyv1], returns empty on failure
Data Parameter Description
Field Type Description
device Array Terminal environment statistics See Device field description
operatingSystem Array Operating system environment statistics See OperatingSystem field description
browser Array Browser environment statistics See Browser field description
Device Parameter Description
Field Type Description
deviceName String Terminal environment name, e.g., PC or Mobile
videoView Integer Total video views
formatPlayDuration String Formatted total play duration, format: HH:mm:ss, e.g., 00:00:00
playDuration Integer Total play duration in seconds
uniqueViewer Integer Total unique viewers
percentage Float Total percentage
OperatingSystem Parameter Description
Field Type Description
operateSystemName String Operating system environment name
videoView Integer Total video views
formatPlayDuration String Formatted total play duration, format: HH:mm:ss, e.g., 00:00:00
playDuration Integer Total play duration in seconds
uniqueViewer Integer Total unique viewers
pcPercentage Float Total percentage
Browser Parameter Description
Field Type Description
browserName String Browser environment name
mobilePlayDuration Integer Mobile play duration in seconds
formatMobilePlayDuration String Formatted mobile play duration, format: HH:mm:ss, e.g., 00:00:00
mobileVideoView Integer Mobile video views
mobileUniqueViewer Integer Mobile unique viewers
mobilePercentage Float Mobile data percentage
pcPlayDuration Integer PC play duration in seconds
formatPcPlayDuration String Formatted PC play duration, format: HH:mm:ss, e.g., 00:00:00
pcVideoView Integer PC video views
pcUniqueViewer Integer PC unique viewers
pcPercentage Float PC data percentage

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 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
401 start and end illegal. Start date is greater than end date
500 query failed. Backend program threw an exception

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(VodStatisticsTest.class);
/**
 * 查询视频播放的终端环境分布
 */
@Test
public void testGetDeviceStat() throws Exception, NoSuchAlgorithmException {
    //公共参数,填写自己的实际参数
    String secretKey = super.secretKey;
    String userId = super.userId;
    String ptime = String.valueOf(System.currentTimeMillis());
    //业务参数
    String url = String.format("https://api.polyv.net/v2/device/%s", userId);
    String dr = "this_year";
    String start = "2021-03-16";
    String end = "2021-03-24";

    Map<String, String> requestMap = new HashMap<>();
    requestMap.put("ptime", ptime);
    requestMap.put("dr", dr);
    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 system error descriptions, see Global Error Description

Success Example

{
    "code": 200,
    "status": "success",
    "message": "success",
    "data": {
        "device": [{
            "deviceName": "PC端",
            "videoView": 17,
            "formatPlayDuration": "00:03:10",
            "playDuration": 190,
            "uniqueViewer": 4,
            "percentage": "80.95"
        }, {
            "deviceName": "移动端",
            "videoView": 4,
            "formatPlayDuration": "00:00:57",
            "playDuration": 57,
            "uniqueViewer": 3,
            "percentage": "19.05"
        }],
        "operatingSystem": [{
            "operateSystemName": "Windows",
            "videoView": 17,
            "formatPlayDuration": "00:03:10",
            "playDuration": 190,
            "uniqueViewer": 4,
            "percentage": "80.95"
        }, {
            "operateSystemName": "Android",
            "videoView": 4,
            "formatPlayDuration": "00:00:57",
            "playDuration": 57,
            "uniqueViewer": 3,
            "percentage": "19.05"
        }],
        "browser": [{
            "browserName": "Chrome",
            "formatPcPlayDuration": "00:02:47",
            "pcPlayDuration": 167,
            "pcVideoView": 14,
            "pcUniqueViewer": 3,
            "formatMobilePlayDuration": "00:00:00",
            "mobilePlayDuration": 0,
            "mobileVideoView": 0,
            "mobileUniqueViewer": 0,
            "pcPercentage": "82.35",
            "mobilePercentage": "0.00"
        }, {
            "browserName": "Firefox",
            "formatPcPlayDuration": "00:00:23",
            "pcPlayDuration": 23,
            "pcVideoView": 3,
            "pcUniqueViewer": 1,
            "formatMobilePlayDuration": "00:00:00",
            "mobilePlayDuration": 0,
            "mobileVideoView": 0,
            "mobileUniqueViewer": 0,
            "pcPercentage": "17.65",
            "mobilePercentage": "0.00"
        }, {
            "browserName": "微信",
            "formatPcPlayDuration": "00:00:00",
            "pcPlayDuration": 0,
            "pcVideoView": 0,
            "pcUniqueViewer": 0,
            "formatMobilePlayDuration": "00:00:57",
            "mobilePlayDuration": 57,
            "mobileVideoView": 4,
            "mobileUniqueViewer": 3,
            "pcPercentage": "0.00",
            "mobilePercentage": "100.00"
        }]
    }
}

Error Example

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