Paginated Query of Channel Viewing Logs (VOD & Live Combined)
Updated: 2022-09-02 18:08:07
Interface URL
http://api.polyv.net/live/v2/statistics/{channelId}/viewlog
Interface Description
1. Purpose: Retrieve channel viewing logs with pagination.
2. The interface supports the HTTPS protocol.
3. The {channelId} in the interface URL represents the Channel ID.
Supported Format
JSON
Request Method
GET
Request Rate Limit
TRUE
Request Parameters
| Parameter | Required | Type | Description |
|---|---|---|---|
| appId | Yes | string | Obtained from API settings, the appId registered in the live streaming system. |
| timestamp | Yes | string | Current 13-digit millisecond timestamp, valid for 3 minutes. |
| page | Yes | string | Page number. |
| pageSize | No | string | Number of data items per page, default is 1000 items per page. |
| currentDay | See note below | string | Query date, format: yyyy-MM-dd. |
| startTime | See note below | string | Query start time, 13-digit millisecond timestamp. |
| endTime | See note below | string | Query end time, 13-digit millisecond timestamp. |
| param1 | No | string | Viewer user ID. |
| param2 | No | string | Viewer user nickname. |
| param3 | No | string | Viewing log type, value vod for playback, live for live stream. |
| sign | Yes | String | Signature, a 32-character uppercase MD5 value. The appSecret key used to generate the signature is critical for communication data security. It must not be stored or used directly on the client side. All APIs must be called through the customer's own server to relay requests to the POLYV server for response data. See signature generation rules |
| viewLogType | No | string | Playback log type, live: live log, vod: VOD log, default value: live. |
Note:
- To query records over a period, pass
startTimeandendTime(must be within the same month). To query records for a specific day, passcurrentDay. startTime,endTime, andcurrentDaycannot all be omitted.- If
currentDayis passed together withstartTimeandendTime, the value ofcurrentDaywill be used.
Successful Response JSON Example:
{
"code": 200,
"status": "success",
"message": "",
"data": {
"pageNumber": 1,
"totalItems": 3,
"contents": [
{
"playId": "1520501687122X1438160",
"userId": "1c6dc3c666",
"channelId": 151462,
"videoId": "3828390191ed924fbb387395ae6f3af5_3",
"playDuration": 341,
"stayDuration": 361,
"flowSize": 10028116,
"sessionId": "eyz0awxrlh",
"param1": "1520499775580",
"param2": "广州观众/78614",
"param3": "live",
"param4": "",
"param5": "",
"ipAddress": "59.42.41.1",
"country": "中国",
"province": "广东",
"city": "广州",
"isp": "/南沙区电信",
"referer": "https://live.polyv.cn/watch/151462",
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36",
"operatingSystem": "Mac OS X",
"browser": "Chrome",
"isMobile": "N",
"currentDay": "2018-03-08",
"createdTime": 1520501705000,
"lastModified": 1520504494000
},
{
"playId": "1520501157256X1429802",
"userId": "1c6dc3c666",
"videoId": "3828390191ed924fbb387395ae6f3af5_3",
"channelId": 151462,
"playDuration": 29,
"stayDuration": 528,
"flowSize": 1068201,
"sessionId": "eyz0awxrlh",
"param1": "1520499775580",
"param2": "广州观众/78614",
"param3": "live",
"param4": "",
"param5": "",
"ipAddress": "59.42.41.1",
"country": "中国",
"province": "广东",
"city": "广州",
"isp": "/南沙区电信",
"referer": "https://live.polyv.cn/watch/151462",
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36",
"operatingSystem": "Mac OS X",
"browser": "Chrome",
"isMobile": "N",
"currentDay": "2018-03-08",
"createdTime": 1520501664000,
"lastModified": 1520504494000
},
{
"playId": "1520500551108X1714565",
"userId": "1c6dc3c666",
"channelId": 151462,
"videoId": "3828390191ed924fbb387395ae6f3af5_3",
"playDuration": 18,
"stayDuration": 20,
"flowSize": 3048444,
"sessionId": "eyz0awxrlh",
"param1": "1520499775580",
"param2": "广州观众/78614",
"param3": "live",
"param4": "",
"param5": "",
"ipAddress": "59.42.40.205",
"country": "中国",
"province": "广东",
"city": "广州",
"isp": "/南沙区电信",
"referer": "https://live.polyv.cn/watch/151462",
"userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36",
"operatingSystem": "Mac OS X",
"browser": "Chrome",
"isMobile": "N",
"currentDay": "2018-03-08",
"createdTime": 1520500572000,
"lastModified": 1520503294000
}
],
"endRow": 3,
"startRow": 1,
"firstPage": true,
"lastPage": true,
"nextPageNumber": 1,
"prePageNumber": 1,
"totalPages": 1,
"limit": 3,
"offset": 0
}
}
Failed Response JSON Examples:
No appId entered
{
"code": 400,
"status": "error",
"message": "appId is required.",
"data": ""
}
Incorrect appId
{
"code": 400,
"status": "error",
"message": "application not found.",
"data": ""
}
Timestamp error
{
"code": 400,
"status": "error",
"message": "invalid timestamp.",
"data": ""
}
Signature error
{
"code": 403,
"status": "error",
"message": "invalid signature.",
"data": ""
}
No currentDay entered
{
"code": 400,
"status": "error",
"message": "currentDay is empty.",
"data": ""
}
Channel does not exist
{
"code": 400,
"status": "error",
"message": "channel not found.",
"data": ""
}
Invalid channel ID
{
"code": 403,
"status": "error",
"message": "invalid channelId.",
"data": ""
}
Field Description
| Parameter | Description |
|---|---|
| code | Response status code, e.g., 200. |
| status | Response status. |
| message | Error message. |
| data | Response result set. |
| pageNumber | Current page number. |
| totalItems | Total number of items. |
| contents | Query result list. |
| playId | ID representing this playback action. |
| userId | User ID. |
| channelId | Channel ID. |
| videoId | Video VID, only output for VOD logs. |
| playDuration | Playback duration. |
| stayDuration | Stay duration. |
| flowSize | Traffic size. |
| sessionId | Live session ID. |
| param1 | Viewer ID from the POLYV viewing page. |
| param2 | Viewer nickname from the POLYV viewing page. |
| param3 | Viewing type: live (live stream) or vod (playback). |
| param4/5 | POLYV system parameters. |
| ipAddress | IP address. |
| country | Country. |
| province | Province. |
| city | City. |
| isp | ISP operator. |
| referer | URL of the video playback page. |
| userAgent | User device. |
| operatingSystem | Operating system. |
| browser | Browser. |
| isMobile | Whether it is a mobile device. |
| currentDay | Log query date (format: yyyy-MM-dd). |
| createdTime | Log creation date (13-digit timestamp). |
| lastModified | Log update date (13-digit timestamp). |
| firstPage | Whether it is the first page, value: true/false. |
| lastPage | Whether it is the last page, value: true/false. |
| nextPageNumber | Next page number. |
| prePageNumber | Previous page number. |
| totalPages | Total number of pages. |
| startRow | Position of the first video on the current page within the playback video list. |
| endRow | Position of the last video on the current page within the playback video list. |
| limit | Number of videos on the current page. |
PHP Request Example
<?php
//引用config.php
include 'config.php';
//接口需要的参数(非sign)赋值
$channelId = "124545";
$currentDay = "2018-03-12";
$page = "1"; //页数
$pageSize="10";//每页显示的数据
$params = array(
'appId'=>$appId,
'currentDay'=>$currentDay,
'page'=>$page,
'pageSize'=>$pageSize,
'timestamp'=>$timestamp
);
//生成sign
$sign = getSign($params); //详细查看config.php文件的getSign方法
//接口请求url
$url = "http://api.polyv.net/live/v2/statistics/$channelId/viewlog?appId=$appId¤tDay=$currentDay&page=$page&pageSize=$pageSize×tamp=$timestamp&sign=$sign";
//输出接口请求结果
echo file_get_contents($url);
?>
