依日期區間或時間段查詢分類的播放量、流量、播放時長統計資訊
更新時間:2022-05-23 18:01:52
介面URL
https://api.polyv.net/v2/cata/{userid}/stats-info
介面說明
依日期區間或時間段查詢分類的播放量、流量、播放時長統計資訊
支援格式
JSON
請求方式
GET
請求參數
| 參數名 | 必選 | 類型及範圍 | 說明 |
|---|---|---|---|
| userid | true | string | 使用者id,路徑參數 |
| ptime | true | string | 當前13位毫秒級時間戳,3分鐘內有效 |
| sign | true | string | 簽名,40位大寫的sha1值 |
| cataid | true | long | 分類ID |
| dr | false | string | 時間段,具體值為以下幾個:today(今天),yesterday(昨天),this_week(本週),last_week(上週),7days(最近7天),this_month(本月),last_month(上個月),this_year(今年),last_year(去年),預設值為7days |
| startDate | false | string | 開始日期,格式為yyyy-MM-dd |
| endDate | false | string | 結束日期,格式為yyyy-MM-dd |
| containSubCategory | false | string | 是否包含子分類的統計資料,取值Y表示包含子分類 ,N表示不包含 |
回傳結果
{
"code": 4,
"status": "text",
"message": "",
"data": [
{
"current": "2018-08-01",
"pcFlowSize": 10,
"mobileFlowSize": 0,
"mobilePlayDuration": 9,
"pcPlayDuration": 2,
"pcVideoView": 9,
"mobileVideoView": 7
},
{
"current": "2018-08-02",
"pcFlowSize": 10,
"mobileFlowSize": 1000,
"mobilePlayDuration": 9,
"pcPlayDuration": 20,
"pcVideoView": 90,
"mobileVideoView": 7
}
]
}
失敗回傳json(不帶jsonp)
{
"code": 400,
"status": "error",
"message": "ptime is too old.",
"data": ""
}
欄位描述
| 欄位名稱 | 描述 |
|---|---|
| current | 查詢的日期 |
| pcFlowSize | pc端流量 |
| mobileFlowSize | 行動端流量 |
| mobilePlayDuration | 行動端播放時長 |
| pcPlayDuration | pc端播放時長 |
| pcVideoView | pc端播放量 |
| mobileVideoView | 行動端播放量 |
回應說明
| 錯誤代碼 | message | 說明 |
|---|---|---|
| 400 | sign can not be empty. | 加密串為空 |
| 402 | illegal cataid. | 分類ID錯誤 |
| 400 | ptime is too old. | 時間戳過期 |
| 400 | ptime is illegal. | 時間戳參數格式不對或超過當前時間3分鐘 |
| 400 | Could not find user by userid. | userid不存在 |
| 400 | the sign is not right. | 加密串不正確 |
| 402 | illegal query date. | start日期大於end日期 |
| 500 | query failed. | 後台程式拋異常 |
| 200 | success | 提交成功 |
PHP請求範例
<?php
header("Content-type: text/html; charset=utf-8");
$userid="用户id";
$dr="this_year";
$cataid="1399488884";
$ptime=time()*1000;//13位
$secretkey="填写secretKey";
$str="cataid=".$cataid."&dr=".$dr."&ptime=".$ptime.$secretkey;
$hash=strtoupper(sha1($str));
$url="http://api.polyv.net/v2/cata/$userid/stats-info?ptime=$ptime&sign=$hash&dr=$dr&cataid=$cataid";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
//打印获得的数据
print_r($output);
?>
簽名規則:
將非空的請求參數按照參數名字典順序排列,連接參數名與參數值,並在尾部加上secretkey,生成40位大寫SHA1值,作為sign。 以下是範例過程:
1、請求參數為
ptime = "1492591990000"
cataid = "1333444444"
format = "json"
2、將請求參數按照參數名字典順序排列
cataid = "1333444444"
format = "json"
ptime = "1492591990000"
3、連接字串 連接參數名與參數值,並在尾部加上secretkey(secretkey的值為tIQp4ATe9Z),如下:
cataid=1333444444&format=json&ptime=1492591990000be68715e9455f8d0971a_3tIQp4ATe9Z
4、生成簽名sign
50BF9B165630A8047EB1D17D95A469CC51FF754E
