保利威文档中心

幫助中心

查詢播放量統計

更新時間:2025-01-14 16:14:34

介面描述

1、查询视频播放量在不同终端的统计数据,从播放行为产生到数据可查询的间隔时间为1~2小时
2、接口URL中的{userid}为点播账号userid,具体参考菜单【使用须知】->【获取密钥】
3、接口支持https协议

介面URL

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

線上API呼叫

請求方式

GET

介面限制

1、介面同時支援HTTP、HTTPS,建議使用HTTPS以確保介面安全,介面呼叫有頻率限制,詳細請查看

2、請求參數period(顯示週期)的值受限於dr的值,當dr的值為today、yesterday、this_week、last_week、7days時,period只能為daily;當dr的值為this_month、last_month時,period只能為daily或weekly

請求參數描述

參數名 必選 類型 說明
ptime true Long 當前時間的毫秒級時間戳,3分鐘內有效
sign true String 簽名,為40位大寫的SHA1值,生成簽名的secretkey金鑰作為通訊資料安全的關鍵資訊,嚴禁儲存在客戶端直接使用,所有API都必須透過客戶自己伺服器中轉呼叫POLYV伺服器取得回應資料【詳見簽名生成規則
vid false String 影片id,不填會查所有影片的播放量統計資料
dr false String 時間段,不傳預設為7days
today:今天
yesterday:昨天
this_week:本週
last_week:上週
7days:最近7天
this_month:本月
last_month:上個月
this_year:今年
last_year:去年
period false String 顯示週期,不傳預設為daily
daily:按日顯示
weekly:按週顯示
monthly:按月顯示

範例

http://api.polyv.net/v2/videoview/1b448be323?vid=1b448be32395861bacc794ca59e8f306_1&sign=AD7527B17D2F2BE5E740F9D3357B7F80231837CE&ptime=1618215907432

回應參數描述

參數名 類型 說明
code Integer 回應狀態碼,200為成功返回,非200為失敗【詳見全域錯誤說明
status String 回應狀態文字資訊
message String 回應描述資訊,當code為400或500時,輔助描述錯誤原因
data Array 回應成功時返回影片播放統計資料的陣列【詳見data欄位說明
Data參數描述
參數名 類型 說明
currentTime String 目前日期,格式為:yyyy-MM-dd
pcVideoView Integer pc端播放量
mobileVideoView 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 illegal vid. vid格式不正確,正確vid格式前面一段是userid
402 illegal period. period的值非法,請看請求參數裡period的限制內容
500 query failed. 後台程式拋異常

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 testGetPlaytimes() throws Exception, NoSuchAlgorithmException {
    //公共参数,填写自己的实际参数
    String secretKey = super.secretKey;
    String userId = super.userId;
    String ptime = String.valueOf(System.currentTimeMillis());
    //业务参数
    String url = "http://api.polyv.net/v2/videoview/" + userId;
    String vid = "1b448be32395861bacc794ca59e8f306_1";

    Map<String, String> requestMap = new HashMap<>();
    requestMap.put("ptime", ptime);
    requestMap.put("vid", vid);
    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":[
        {
            "currentTime":"2021-04-06",
            "pcVideoView":0,
            "mobileVideoView":0
        },
        {
            "currentTime":"2021-04-07",
            "pcVideoView":0,
            "mobileVideoView":0
        },
        {
            "currentTime":"2021-04-08",
            "pcVideoView":0,
            "mobileVideoView":0
        },
        {
            "currentTime":"2021-04-09",
            "pcVideoView":0,
            "mobileVideoView":0
        },
        {
            "currentTime":"2021-04-10",
            "pcVideoView":0,
            "mobileVideoView":0
        },
        {
            "currentTime":"2021-04-11",
            "pcVideoView":0,
            "mobileVideoView":0
        },
        {
            "currentTime":"2021-04-12",
            "pcVideoView":0,
            "mobileVideoView":0
        }
    ]
}

異常範例

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