查詢影片播放的時段分佈
更新時間:2025-01-14 16:17:54
介面說明
1、通过时间范围查询用户视频播放时段统计数据,播放后生成数据需间隔一到两小时,其中流量数据间隔一个自然日生成
2、接口URL中的{userid}为点播账号userid,具体参考菜单【使用须知】->【获取密钥】
3、接口支持https协议
介面URL
http://api.polyv.net/v2/hourly/{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,最近7天 today:今天 yesterday:昨天 this_week:本週 last_week:上週 7days:最近7天 this_month:本月 last_month:上個月 this_year:今年 last_year:去年 |
| start | false | String | 開始日期,格式為yyyy-MM-dd,例如:2021-03-31 |
| end | false | String | 結束日期,格式為yyyy-MM-dd,例如:2021-04-02 |
範例
http://api.polyv.net/v2/hourly/1b448be323?sign=571A6C9924A207BF92635FE5661144844519E0F2&ptime=1617785134079&dr=last_month
回應參數說明
| 參數名 | 類型 | 說明 |
|---|---|---|
| code | Integer | 回應狀態碼,200為成功返回,非200為失敗【詳見全域錯誤說明】 |
| status | String | 回應狀態文字資訊 |
| message | String | 回應描述資訊,當code為400或500時,輔助描述錯誤原因 |
| data | Array | 回應成功返回影片播放時段統計資料,回應失敗返回空【詳見data欄位說明】 |
data參數說明
| 欄位 | 類型 | 說明 |
|---|---|---|
| currentHour | Integer | 播放時段,單位小時 |
| formatPcPlayDuration | String | pc播放時長,格式為:時:分:秒 |
| pcPlayDuration | Integer | pc播放時長,單位為秒 |
| pcFlowSize | Long | pc消耗流量,單位為位元組 |
| pcVideoView | Integer | pc端播放量 |
| pcUniqueViewer | Integer | pc端唯一觀眾量 |
| formatMobilePlayDuration | String | 行動端播放時長,格式為:時:分:秒 |
| mobilePlayDuration | Integer | 行動端播放時長,單位為秒 |
| mobileFlowSize | Long | 行動端消耗流量,單位為位元組 |
| mobileVideoView | Integer | 行動端播放量 |
| mobileUniqueViewer | Integer | 行動端唯一觀眾量 |
返回錯誤代碼列表
| 錯誤代碼 | 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日期 |
Java請求範例
快速接入基礎代碼請下載相關依賴原始碼, 點擊下載原始碼 ,下載後加入到自己的原始碼工程中即可。測試用例中的HttpUtil.java 和 VodSignUtil.java 都包含在下載檔案中。
強烈建議您使用點播Java SDK完成API的功能對接,點播Java SDK 對API呼叫邏輯、異常處理、資料簽名、HTTP請求執行緒池進行了統一封裝和最佳化。
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
}
回應範例
系統全域錯誤說明詳見全域錯誤說明
成功範例
{
"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
}
]
}
異常範例
{
"code": 400,
"status": "error",
"message": "ptime is too old.",
"data": ""
}
