保利威文档中心

幫助中心

查詢播放時長統計

更新時間:2025-01-14 16:15:31

介面描述

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

介面URL

http://api.polyv.net/v2/play-duration/{userid}

線上API呼叫

請求方式

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伺服器獲取回應資料【詳見簽名生成規則
vid false String 影片id,不傳則查詢用戶所有影片的播放時長資料
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-30
end false String 結束日期,格式為yyyy-MM-dd,例如:2021-04-01

範例

http://api.polyv.net/v2/play-duration/1b448be323?vid=1b448be323b8d9b9489dcd7e8e09f087_1&start=2021-03-30&sign=645AB5A43A556E6D6AF8A577C287266E0BC822D1&end=2021-04-01&ptime=1617767033059

回應參數描述

參數名 類型 說明
code Integer 回應狀態碼,200為成功返回,非200為失敗【詳見全域錯誤說明
status String 回應狀態文字資訊
message String 回應描述資訊,當code為400或500時,輔助描述錯誤原因
data Array 回應成功返回影片播放時長統計資料,回應失敗返回空【詳見data欄位說明

data參數描述

欄位 類型 說明
currentDay String 資料生成日期,格式為:yyyy-MM-dd
pcPlayDuration Integer PC端播放時長,單位秒
formatPcPlayDuration String 格式化的PC端播放時長,格式為:時:分:秒
pcPlayDurationVideoAvg Integer PC端影片平均播放時長,單位秒
formatPcPlayDurationVideoAvg String 格式化的PC端影片平均播放時長,格式為:時:分:秒
pcPlayDurationPersonAvg Integer PC端人均播放時長,單位秒
formatPcPlayDurationPersonAvg String 格式化的PC端人均播放時長,格式為:時:分:秒
mobilePlayDuration Integer 行動端播放時長,單位秒
formatMobilePlayDuration String 格式化的行動端播放時長,格式為:時:分:秒
mobilePlayDurationVideoAvg Integer 行動端影片平均播放時長,單位秒
formatMobilePlayDurationVideoAvg String 格式化的行動端影片平均播放時長,格式為:時:分:秒
mobilePlayDurationPersonAvg Integer 行動端人均播放時長,單位秒
formatMobilePlayDurationPersonAvg String 格式化的行動端人均播放時長,格式為:時:分:秒

返回錯誤代碼列表

錯誤代碼 message 說明
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 testGetPlayDuration() 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/play-duration/%s", userId);
    String vid = "1b448be323b8d9b9489dcd7e8e09f087_1";
    String dr = "last_month";
    String start = "2021-03-30";
    String end = "2021-04-01";
    
    Map<String, String> requestMap = new HashMap<>();
    requestMap.put("ptime", ptime);
    requestMap.put("vid", vid);
    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": [
        {
            "currentDay": "2021-03-30",
            "pcPlayDuration": 0,
            "formatPcPlayDuration": "00:00:00",
            "pcPlayDurationVideoAvg": 0,
            "formatPcPlayDurationVideoAvg": "00:00:00",
            "pcPlayDurationPersonAvg": 0,
            "formatPcPlayDurationPersonAvg": "00:00:00",
            "mobilePlayDuration": 0,
            "formatMobilePlayDuration": "00:00:00",
            "mobilePlayDurationVideoAvg": 0,
            "formatMobilePlayDurationVideoAvg": "00:00:00",
            "mobilePlayDurationPersonAvg": 0,
            "formatMobilePlayDurationPersonAvg": "00:00:00"
        },
        {
            "currentDay": "2021-03-31",
            "pcPlayDuration": 1,
            "formatPcPlayDuration": "00:00:01",
            "pcPlayDurationVideoAvg": 1,
            "formatPcPlayDurationVideoAvg": "00:00:01",
            "pcPlayDurationPersonAvg": 1,
            "formatPcPlayDurationPersonAvg": "00:00:01",
            "mobilePlayDuration": 0,
            "formatMobilePlayDuration": "00:00:00",
            "mobilePlayDurationVideoAvg": 0,
            "formatMobilePlayDurationVideoAvg": "00:00:00",
            "mobilePlayDurationPersonAvg": 0,
            "formatMobilePlayDurationPersonAvg": "00:00:00"
        },
        {
            "currentDay": "2021-04-01",
            "pcPlayDuration": 0,
            "formatPcPlayDuration": "00:00:00",
            "pcPlayDurationVideoAvg": 0,
            "formatPcPlayDurationVideoAvg": "00:00:00",
            "pcPlayDurationPersonAvg": 0,
            "formatPcPlayDurationPersonAvg": "00:00:00",
            "mobilePlayDuration": 0,
            "formatMobilePlayDuration": "00:00:00",
            "mobilePlayDurationVideoAvg": 0,
            "formatMobilePlayDurationVideoAvg": "00:00:00",
            "mobilePlayDurationPersonAvg": 0,
            "formatMobilePlayDurationPersonAvg": "00:00:00"
        }
    ]
}

異常範例

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