查詢影片播放的終端環境分佈
更新時間:2025-01-14 16:19:48
介面描述
1、查询视频终端环境统计数据,包括浏览器环境,操作系统环境,终端环境。从播放行为产生到数据可查询的间隔时间为1~2小时
2、接口URL中的{userid}为点播账号userid,具体参考【获取密钥】
3、接口支持https协议
介面URL
http://api.polyv.net/v2/device/{userid}
請求方式
GET
介面限制
1、介面同時支援HTTP、HTTPS,建議使用HTTPS確保介面安全,介面呼叫有頻率限制,詳細請查看
2、請求參數中start(開始日期)與end(結束日期)需要同時傳入,僅傳一個參數不生效
3、同時傳入dr(時間段)與start、end的情況下,僅start、end有效;都不傳則dr為預設值7days
請求參數描述
| 參數名 | 必選 | 類型 | 說明 |
|---|---|---|---|
| ptime | true | Long | 當前時間的毫秒級時間戳,3分鐘內有效 |
| sign | true | String | 簽名,為40位大寫的SHA1值,產生簽名的secretkey金鑰作為通訊資料安全的關鍵資訊,嚴禁儲存在客戶端直接使用,所有API都必須透過客戶自己伺服器中轉呼叫POLYV伺服器獲取回應資料【詳見簽名產生規則】 |
| dr | false | String | 時間段,具體值為以下幾個,預設值為7days today:今天 yesterday:昨天 this_week:本週 last_week:上週 7days:最近7天 this_month:本月 last_month:上個月 this_year:今年 last_year:去年 |
| start | false | String | 開始日期,格式為:yyyy-MM-dd,例如:2021-04-07 |
| end | false | String | 結束日期,格式為:yyyy-MM-dd,例如:2021-04-10 |
範例
http://api.polyv.net/v2/device/1b448be323?start=2021-03-16&sign=F3A24F3621CE3D0B0B5366E56D95A6E3CF34B2AA&end=2021-03-24&ptime=1617875576619&dr=this_year
回應參數描述
| 參數名 | 類型 | 說明 |
|---|---|---|
| code | Integer | 回應狀態碼,200為成功返回,非200為失敗【詳見全域錯誤說明】 |
| status | String | 回應狀態文字資訊 |
| message | String | 回應描述資訊,當code為400或者500的時候,輔助描述錯誤原因 |
| data | Object | 回應成功時返回網域名稱統計資訊【詳見Data欄位說明】,回應失敗時返回空 |
Data參數描述
| 欄位 | 類型 | 說明 |
|---|---|---|
| device | Array | 終端環境統計資料【詳見Device欄位說明】 |
| operatingSystem | Array | 作業系統環境統計資料【詳見OperatingSystem欄位說明】 |
| browser | Array | 瀏覽器環境統計資料【詳見Browser欄位說明】 |
Device參數描述
| 欄位 | 類型 | 說明 |
|---|---|---|
| deviceName | String | 終端環境名稱,PC端或行動端 |
| videoView | Integer | 影片總播放量 |
| formatPlayDuration | String | 格式化的總播放時長,格式為:時:分:秒,例如:00:00:00 |
| playDuration | Integer | 影片總播放時長,單位秒 |
| uniqueViewer | Integer | 影片總觀眾數 |
| percentage | Float | 總佔比 |
OperatingSystem參數描述
| 欄位 | 類型 | 說明 |
|---|---|---|
| operateSystemName | String | 作業系統環境名稱 |
| videoView | Integer | 影片總播放量 |
| formatPlayDuration | String | 格式化的總播放時長,格式為:時:分:秒,例如:00:00:00 |
| playDuration | Integer | 影片總播放時長,單位秒 |
| uniqueViewer | Integer | 影片總觀眾數 |
| pcPercentage | Float | 總佔比 |
Browser參數描述
| 欄位 | 類型 | 說明 |
|---|---|---|
| browserName | String | 瀏覽器環境名稱 |
| mobilePlayDuration | Integer | 行動端播放時長,單位秒 |
| formatMobilePlayDuration | String | 格式化的行動端播放時長,格式為:時:分:秒,例如:00:00:00 |
| mobileVideoView | Integer | 行動端播放量 |
| mobileUniqueViewer | Integer | 行動端唯一觀眾數 |
| mobilePercentage | Float | 行動端資料佔比 |
| pcPlayDuration | Integer | PC端播放時長,單位秒 |
| formatPcPlayDuration | String | 格式化的PC端播放時長,格式為:時:分:秒,例如:00:00:00 |
| pcVideoView | Integer | PC端播放量 |
| pcUniqueViewer | Integer | PC端唯一觀眾數 |
| pcPercentage | Float | PC端資料佔比 |
返回錯誤代碼列表
| 錯誤代碼 | message | 說明 |
|---|---|---|
| 400 | sign can not be empty. | 加密串為空 |
| 400 | ptime is too old. | 時間戳過期 |
| 400 | ptime is illegal. | 時間戳參數格式不對或者超過當前時間3分鐘 |
| 400 | Could not find user by userid. | userid不存在 |
| 400 | the sign is not right. | 加密串不正確 |
| 401 | start and end illegal. | start日期大於end日期 |
| 500 | query failed. | 後台程式拋異常 |
Java請求範例
快速接入基礎代碼請下載相關依賴原始碼, 點擊下載原始碼 ,下載後加入到自己的原始碼工程中即可。測試用例中的HttpUtil.java 和 VodSignUtil.java 都包含在下載檔案中。
強烈建議您使用點播Java SDK完成API的功能對接,點播Java SDK 對API呼叫邏輯、異常處理、資料簽名、HTTP請求執行緒池進行了統一封裝和最佳化。
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
}
回應範例
系統全域錯誤說明詳見全域錯誤說明
成功範例
{
"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"
}]
}
}
異常範例
{
"code": 400,
"status": "error",
"message": "ptime is too old.",
"data": ""
}
