# 分页查询频道直播观看详情数据

### 接口描述

```
1、分页获取频道的直播观看日志
2、接口URL中的{channelId}为频道号
3、接口支持https协议
```

### 接口URL

```
http://api.polyv.net/live/v2/statistics/{channelId}/viewlog
```

[在线API调用](https://git.polyv.net/help-center/document-center/-/blob/master/req.html?api=http:/api.polyv.net/live/v2/statistics/%7BchannelId%7D/viewlog/README.md)

### 请求方式

```
GET
```

### 接口约束

1、接口同时支持HTTP 、HTTPS ，建议使用HTTPS 确保接口安全，接口调用有频率限制，[详细请查看](https://git.polyv.net/help-center/document-center/-/blob/master/live/api/limit/README.md)

2、如果查询一段时间的记录，可以传：startTime、endTime （startTime和endTime 必须在同一个月），如果查询某天的记录，则传currentDay

3、startTime、endTime 和 currentDay不能都不传

4、currentDay与startTime、endTime 同时传将使用currentDay的值

5、观看时长数据的生成有3-5分钟的延迟

### 请求参数描述

| 参数名         | 必选    | 类型     | 说明                                                                                                                                                                                                        |
| ----------- | ----- | ------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| appId       | true  | String | 账号appid【详见[获取密钥](https://git.polyv.net/help-center/document-center/-/blob/master/live/api/getSecretKey/README.md)】                                                                                        |
| timestamp   | true  | Long   | 当前13位毫秒级时间戳，3分钟内有效                                                                                                                                                                                        |
| sign        | true  | String | 签名，为32位大写的MD5值,`生成签名的appSecret密钥作为通信数据安全的关键信息，严禁保存在客户端直接使用，所有API都必须通过客户自己服务器中转调用POLYV服务器获取响应数据`【详见[签名生成规则](https://git.polyv.net/help-center/document-center/-/blob/master/live/api/buildSign/README.md)】 |
| page        | false | String | 当前页码，默认为1                                                                                                                                                                                                 |
| currentDay  | false | String | 查询日期，格式：yyyy-MM-dd                                                                                                                                                                                        |
| pageSize    | false | String | 每页显示的数据条数，默认每页显示1000条数据                                                                                                                                                                                   |
| startTime   | false | String | 查询开始时间，为13位毫秒级时间戳                                                                                                                                                                                         |
| endTime     | false | String | 查询结束时间，13位毫秒级时间戳                                                                                                                                                                                          |
| param1      | false | String | 观看用户ID，默认查询全部                                                                                                                                                                                             |
| param2      | false | String | 观看用户昵称，默认查询全部                                                                                                                                                                                             |
| param3      | false | String | <p>观看日志类型，默认查询全部<br>vod：观看回放<br>live：直播</p>                                                                                                                                                               |
| viewLogType | false | String | <p>直播点播日志类型，默认为live<br>vod：查询点播列表观看数据<br>live：查询直播或回放列表观看数据</p>                                                                                                                                           |
| sessionIds  | false | String | 场次ID, 多个场次使用,分隔                                                                                                                                                                                           |

### 示例

```requestUrl
http://api.polyv.net/live/v2/statistics/1965681/viewlog?currentDay=2021-1-20&appId=frlr1zazn3&sign=B16CE5B5F2FCCBDB37F4F374BB98B329&pageSize=10&startTime=1611072000000&page=1&endTime=1611158400000&param3=live&param1=1b448be323&timestamp=1621842645601&param2=%E7%AE%A1%E7%90%86%E5%91%98
```

### 响应参数描述

| 参数名     | 类型      | 说明                                                                                                                                                           |
| ------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| code    | Integer | 响应状态码，200为成功返回，非200为失败【详见[全局错误说明](https://git.polyv.net/help-center/document-center/-/blob/master/live/api/errorInfo/README.md)】                             |
| status  | String  | 响应状态文本信息                                                                                                                                                     |
| message | String  | 响应描述信息，当code为400或者500的时候，辅助描述错误原因                                                                                                                            |
| data    | Object  | 请求成功时为直播观看日志有关信息 【详见[Data参数描述](https://git.polyv.net/help-center/document-center/-/blob/master/live/api/channel/viewdata/viewlog_page.md?id=polyv1)】，请求失败时为空 |

[**Data参数描述**](#/live/api/channel/viewdata/viewlog_page.md?id=polyv1)

| 参数名            | 类型      | 说明                                                                                                                                             |
| -------------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| pageSize       | Integer | 每页显示的数据条数，默认每页显示1000条数据                                                                                                                        |
| pageNumber     | Integer | 当前的页数                                                                                                                                          |
| totalItems     | Integer | 总的条数                                                                                                                                           |
| contents       | Array   | 查询的结果列表【详见[Contents参数描述](https://git.polyv.net/help-center/document-center/-/blob/master/live/api/channel/viewdata/viewlog_page.md?id=polyv2)】 |
| startRow       | Integer | 当前页第一条记录在总结果集中的位置                                                                                                                              |
| firstPage      | Boolean | 是否为第一页，值为：true/false                                                                                                                           |
| lastPage       | Boolean | 是否为最后一页，值为：true/false                                                                                                                          |
| prePageNumber  | Integer | 上一页编号                                                                                                                                          |
| nextPageNumber | Integer | 下一页编号                                                                                                                                          |
| limit          | Integer | 每页数量大小                                                                                                                                         |
| totalPages     | Integer | 总页数                                                                                                                                            |
| endRow         | Integer | 当前页最后一条记录在总结果集中的位置                                                                                                                             |
| offset         | Integer | 分页起始记录                                                                                                                                         |

[**Contents参数描述**](#/live/api/channel/viewdata/viewlog_page.md?id=polyv2)

| 参数名             | 类型      | 说明                                                            |
| --------------- | ------- | ------------------------------------------------------------- |
| playId          | String  | 表示此次播放动作的ID                                                   |
| userId          | String  | 用户ID                                                          |
| channelId       | String  | 频道号                                                           |
| playDuration    | Integer | 播放时长，单位：秒                                                     |
| stayDuration    | Integer | 停留时长，单位：秒                                                     |
| flowSize        | Long    | 流量大小，单位：bytes                                                 |
| sessionId       | String  | 直播场次ID                                                        |
| param1          | String  | 使用POLYV观看页的观众ID                                               |
| param2          | String  | 使用POLYV观看页的观众昵称                                               |
| param3          | String  | <p>观看日志类型，默认为live<br>vod：观看回放<br>live：直播</p>                  |
| param4          | String  | POLYV系统参数                                                     |
| param5          | String  | POLYV系统参数                                                     |
| ipAddress       | String  | IP地址                                                          |
| country         | String  | 国家                                                            |
| province        | String  | 省份                                                            |
| city            | String  | 城市                                                            |
| isp             | String  | ISP运营商                                                        |
| referer         | String  | 播放视频页面地址                                                      |
| userAgent       | String  | 用户设备                                                          |
| operatingSystem | String  | 操作系统                                                          |
| browser         | String  | 浏览器                                                           |
| isMobile        | String  | 是否为移动端                                                        |
| currentDay      | String  | 查询日期，格式：yyyy-MM-dd                                            |
| ptype           | Integer | <p>0 或者不传：普通直播<br>1：超低延迟直播 rts （已经没有在使用）<br>2：PRTC直播（无延迟）</p> |
| firstActiveTime | Long    | 进入时间，13位毫秒级时间戳                                                |
| lastActiveTime  | Long    | 退出时间，13位毫秒级时间戳                                                |

### Java请求示例

快速接入基础代码请下载相关依赖源码， [点击下载源代码](https://git.polyv.net/help-center/document-center/-/blob/master/third_res/util.zip) ,下载后加入到自己的源码工程中即可。测试用例中的**HttpUtil.java 和 LiveSignUtil.java** 都包含在下载文件中。

> 强烈建议您使用[直播Java SDK](https://git.polyv.net/help-center/document-center/-/blob/master/live/java/README.md)完成API的功能对接，直播Java SDK 对API调用逻辑、异常处理、数据签名、HTTP请求线程池进行了统一封装和优化。

```java
private static final Logger log = LoggerFactory.getLogger(ChannelViewDataTest.class);
/**
 * 分页查询频道直播观看详情数据
 * @throws IOException
 */
@Test
public void testPageViewlog() throws IOException, NoSuchAlgorithmException {
    //公共参数,填写自己的实际参数
    String appId = super.appId;
    String appSecret = super.appSecret;
    String userId = super.userId;
    String timestamp = String.valueOf(System.currentTimeMillis());
    //业务参数
    String url = String.format("http://api.polyv.net/live/v2/statistics/%s/viewlog","1965681");
    String currentDay = "2021-1-20";
    String page = "1";
    String pageSize = "10";
    String startTime = "1611072000000";
    String endTime = "1611158400000";
    String param1 = "1b448be323";
    String param2 = "管理员";
    String param3 = "live";

    //http 调用逻辑
    Map<String,String> requestMap = new HashMap<>();
    requestMap.put("appId", appId);
    requestMap.put("timestamp",timestamp);
    requestMap.put("currentDay",currentDay);
    requestMap.put("page",page);
    requestMap.put("pageSize",pageSize);
    requestMap.put("startTime",startTime);
    requestMap.put("endTime",endTime);
    requestMap.put("param1",param1);
    requestMap.put("param2",param2);
    requestMap.put("param3",param3);
    requestMap.put("sign",LiveSignUtil.getSign(requestMap, appSecret));
    String response = HttpUtil.get(url, requestMap);
    log.info("测试分页查询频道直播观看详情数据，返回值：{}",response);
    //do somethings

}
```

### 响应示例

系统全局错误说明详见[全局错误说明](https://git.polyv.net/help-center/document-center/-/blob/master/live/api/errorInfo/README.md)

成功示例

```json
{
    "code":200,
    "status":"success",
    "message":"",
    "data":{
        "pageSize":10,
        "pageNumber":1,
        "totalItems":2,
        "contents":[
            {
                "playId":"1611137360114X1320926",
                "userId":"1b448be323",
                "channelId":1965681,
                "playDuration":182,
                "stayDuration":190,
                "flowSize":0,
                "sessionId":"fv3ma84e63",
                "param1":"1b448be323",
                "param2":"管理员",
                "param3":"live",
                "param4":"",
                "param5":"",
                "ipAddress":"118.249.213.240",
                "country":"中国",
                "province":"湖南",
                "city":"长沙",
                "isp":"湖南电信",
                "referer":"https://live.polyv.net/#/channel/1965681/monitoring",
                "userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0",
                "operatingSystem":"Windows",
                "browser":"Firefox 8",
                "isMobile":"N",
                "currentDay":"2021-01-20",
                "createdTime":1611137461000,
                "lastModified":1611148800000,
                "ptype":0
            },
            {
                "playId":"1611127231433X1037457",
                "userId":"1b448be323",
                "channelId":1965681,
                "playDuration":154,
                "stayDuration":160,
                "flowSize":0,
                "sessionId":"fv3hmq3qml",
                "param1":"1b448be323",
                "param2":"管理员",
                "param3":"live",
                "param4":"",
                "param5":"",
                "ipAddress":"118.249.213.240",
                "country":"中国",
                "province":"湖南",
                "city":"长沙",
                "isp":"湖南电信",
                "referer":"https://live.polyv.net/#/channel/1965681/monitoring",
                "userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0",
                "operatingSystem":"Windows",
                "browser":"Firefox 8",
                "isMobile":"N",
                "currentDay":"2021-01-20",
                "createdTime":1611127282000,
                "lastModified":1611138733000,
                "ptype":0
            }
        ],
        "startRow":1,
        "firstPage":true,
        "lastPage":true,
        "prePageNumber":1,
        "limit":2,
        "totalPages":1,
        "nextPageNumber":1,
        "endRow":2,
        "offset":0
    }
}
```

异常示例

```json
{
    "code": 400,
    "status": "error",
    "message": "invalid signature.",
    "data": ""
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://polyv.gitbook.io/document/docs/live/api/channel/viewdata/viewlog_page.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
