查詢多個頻道即時並發數據
更新時間:2023-11-21 18:34:54
介面說明
1、获取多个频道实时在线人数
2、接口支持https协议
介面URL
http://api.polyv.net/live/v2/statistics/get-realtime-viewers
請求方式
GET
介面限制
1、介面同時支援HTTP、HTTPS,建議使用HTTPS確保介面安全,介面呼叫有頻率限制,詳細請查看
2、每個頻道回傳最近一段時間內(例如:10秒一個點,15筆資料,這個時間段可能會做調整,呼叫介面請不要寫死筆數。)的即時線上人數資訊。每個頻道的結果列表按照時間降序排序。
請求參數說明
| 參數名 | 必填 | 類型 | 說明 |
|---|---|---|---|
| appId | true | String | 帳號appId【詳見取得金鑰】 |
| timestamp | true | Long | 當前13位毫秒級時間戳,3分鐘內有效 |
| sign | true | String | 簽名,為32位大寫的MD5值,產生簽名的appSecret金鑰作為通訊資料安全的關鍵資訊,嚴禁保存在用戶端直接使用,所有API都必須透過客戶自己伺服器中轉呼叫POLYV伺服器取得回應資料【詳見簽名產生規則】 |
| channelIds | true | String | 多個頻道號,用逗號分隔 |
範例
https://api.polyv.net/live/v2/statistics/get-realtime-viewers?appId=frlr1zazn3&sign=D0B0EF94D4790B08EB6AE800A22497B8&channelIds=1965681%2C2149813&userId=1b448be323×tamp=1621842353153
回應參數說明
| 參數名 | 類型 | 說明 |
|---|---|---|
| code | Integer | 回應狀態碼,200為成功回傳,非200為失敗【詳見全域錯誤說明】 |
| status | String | 回應狀態文字資訊 |
| message | String | 回應描述資訊,當code為400或500時,輔助描述錯誤原因 |
| data | Arrray | 請求成功時為頻道即時線上人數資訊【詳見Data參數說明】,請求失敗時為空 |
Data參數說明
| 參數名 | 類型 | 說明 |
|---|---|---|
| channelId | String | 頻道號 |
| count | Integer | 數字格式,線上人數 |
| time | String | 統計的時間,格式:HH:mm:ss |
Java請求範例
快速接入基礎程式碼請下載相關依賴原始碼, 點擊下載原始碼 ,下載後加入到自己的原始碼工程中即可。測試案例中的HttpUtil.java 和 LiveSignUtil.java 都包含在下載檔案中。
強烈建議您使用直播Java SDK完成API的功能對接,直播Java SDK 對API呼叫邏輯、異常處理、資料簽名、HTTP請求執行緒池進行了統一封裝和最佳化。
private static final Logger log = LoggerFactory.getLogger(ChannelViewDataTest.class);
/**
* 查询多个频道实时并发数据
* @throws IOException
*/
@Test
public void testGetRealtimeViewers() throws IOException, NoSuchAlgorithmException {
//公共参数,填写自己的实际参数
String appId = super.appId;
String appSecret = super.appSecret;
String userId = super.userId;
String timestamp = String.valueOf(System.currentTimeMillis());
//业务参数
String url = "https://api.polyv.net/live/v2/statistics/get-realtime-viewers";
String channelIds = "1965681,2149813";
//http 调用逻辑
Map<String,String> requestMap = new HashMap<>();
requestMap.put("appId", appId);
requestMap.put("timestamp",timestamp);
requestMap.put("channelIds",channelIds);
requestMap.put("sign",LiveSignUtil.getSign(requestMap, appSecret));
String response = HttpUtil.get(url, requestMap);
log.info("测试查询多个频道实时并发数据,返回值:{}",response);
//do somethings
}
回應範例
系統全域錯誤說明詳見全域錯誤說明
成功範例
{
"code":200,
"status":"success",
"message":"",
"data":[
{
"channelId":1965681,
"time":"14:15:49",
"count":0
},
{
"channelId":1965681,
"time":"14:15:39",
"count":0
},
{
"channelId":1965681,
"time":"14:15:29",
"count":0
},
{
"channelId":1965681,
"time":"14:15:19",
"count":0
},
{
"channelId":1965681,
"time":"14:15:09",
"count":0
},
{
"channelId":1965681,
"time":"14:14:59",
"count":0
},
{
"channelId":1965681,
"time":"14:14:49",
"count":0
},
{
"channelId":1965681,
"time":"14:14:39",
"count":0
},
{
"channelId":1965681,
"time":"14:14:29",
"count":0
},
{
"channelId":1965681,
"time":"14:14:19",
"count":0
},
{
"channelId":1965681,
"time":"14:14:09",
"count":0
},
{
"channelId":1965681,
"time":"14:13:59",
"count":0
},
{
"channelId":1965681,
"time":"14:13:49",
"count":0
},
{
"channelId":1965681,
"time":"14:13:39",
"count":0
},
{
"channelId":1965681,
"time":"14:13:29",
"count":0
},
{
"channelId":2149813,
"time":"14:15:49",
"count":0
},
{
"channelId":2149813,
"time":"14:15:39",
"count":0
},
{
"channelId":2149813,
"time":"14:15:29",
"count":0
},
{
"channelId":2149813,
"time":"14:15:19",
"count":0
},
{
"channelId":2149813,
"time":"14:15:09",
"count":0
},
{
"channelId":2149813,
"time":"14:14:59",
"count":0
},
{
"channelId":2149813,
"time":"14:14:49",
"count":0
},
{
"channelId":2149813,
"time":"14:14:39",
"count":0
},
{
"channelId":2149813,
"time":"14:14:29",
"count":0
},
{
"channelId":2149813,
"time":"14:14:19",
"count":0
},
{
"channelId":2149813,
"time":"14:14:09",
"count":0
},
{
"channelId":2149813,
"time":"14:13:59",
"count":0
},
{
"channelId":2149813,
"time":"14:13:49",
"count":0
},
{
"channelId":2149813,
"time":"14:13:39",
"count":0
},
{
"channelId":2149813,
"time":"14:13:29",
"count":0
}
]
}
異常範例
{
"code": 400,
"status": "error",
"message": "invalid signature.",
"data": ""
}
