Polyv Help Center

Help Center

Get Live Room Audience Statistics

Updated: 2022-09-02 18:08:07

API Description

1、获取直播间观众统计数据
2、接口支持https协议

API URL

http://api.polyv.net/live/v3/channel/statistics/listViewLogs

Request Method

GET

API Constraints

  1. The API supports both HTTP and HTTPS. HTTPS is recommended for security. API calls have frequency limits. See details

Request Parameters

Parameter Required Type Description
appId true String Account appId See Get Secret Key
timestamp true Long Current 13-digit millisecond timestamp, valid for 3 minutes
sign true String Signature, a 32-character uppercase MD5 value. The appSecret key used to generate the signature is critical for communication data security. It must never be stored or used directly on the client side. All API calls must be relayed through your own server to the POLYV server to obtain response data. See Signature Generation Rules
channelId true String Channel ID
startTime true Long Start time, 13-digit millisecond timestamp
endTime true Long End time, 13-digit millisecond timestamp (Only data within the same month as the start time can be queried; for cross-month queries, make separate requests)
pageSize false Integer Number of items per page, default 10; minimum 10; maximum 1000
pageNumber false Integer Current page number, default 1

Example

http://api.polyv.net/live/v3/channel/statistics/listViewLogs?appId=f2zgpeyx00&timestamp=1638179488464&sign=C55D7D032E3FFB28324442C4DF74C6B2&startTime=1633017600000&endTime=1638288000000&channelId=2000007&pageSize=10&pageNumber=1

Response Parameters

Parameter Type Description
code Integer Response status code, 200 for success, non-200 for failure See Global Error Description
status String Response status text
message String Response description, provides error details when code is 400 or 500
data Object Response data

data Parameters

Parameter Type Description
pageNumber Integer Current page number
pageSize Integer Number of items per page
totalPages Long Total number of pages
totalItems Long Total number of items
contents Array Content of the current page See contents field description

contents Parameters

Parameter Type Description
param1 String User ID
param2 String User nickname
param3 String Viewing type: vod (playback); live (live stream)
province String Region
city String City
ipAddress String Viewer IP
createdTime number Entry time, 13-digit millisecond timestamp
endTime number Exit time, 13-digit millisecond timestamp
playDuration number Viewing duration (in seconds)
browser String Viewing terminal
sessionId String Session

Java Request Example

For quick integration, download the relevant dependency source code. Click to download source code. After downloading, add it to your project. The test cases include HttpUtil.java and LiveSignUtil.java in the downloaded file.

It is strongly recommended to use the Live Java SDK for API integration. The Live Java SDK provides unified encapsulation and optimization for API call logic, exception handling, data signing, and HTTP request thread pools.

private static final Logger log = LoggerFactory.getLogger(GetCdnViewLog.class);
/**
 * 获取直播间观众统计数据
 * @throws IOException
 * @throws NoSuchAlgorithmException
 */
@Test
public void testGetCdnViewLog() throws IOException, NoSuchAlgorithmException {
    //公共参数,填写自己的实际参数
    String appId = super.appId;
    String appSecret = super.appSecret;
    String userId = super.userId;
    String timestamp = String.valueOf(System.currentTimeMillis());
    //业务参数
    String url = "http://api.polyv.net/live/v3/channel/statistics/listViewLogs";
    String channelId = "2377623";
    long startTime = 1633017600000L;
    long endTime = 1635696000000L;
    int pageSize = 1;
    int pageNumber = 10;

    //http 调用逻辑
    Map<String,String> requestMap = new HashMap<>();
    requestMap.put("appId", appId);
    requestMap.put("timestamp",timestamp);
    requestMap.put("channelId",channelId);
    requestMap.put("startTime",String.valueOf(startTime));
    requestMap.put("endTime",String.valueOf(endTime));
    requestMap.put("pageSize",String.valueOf(pageSize));
    requestMap.put("startTime",String.valueOf());
    requestMap.put("pageNumber",String.valueOf(pageNumber));
    requestMap.put("sign",LiveSignUtil.getSign(requestMap, appSecret));
    String response = HttpUtil.get(url, requestMap);
    log.info("测试获取直播间观众统计数据返回值:{}",response);
    //do somethings
    
}

Response Example

For global error descriptions, see Global Error Description

Success Example

{
  "code": 200,
  "status": "success",
  "message": "",
  "data": {
    "pageSize": 10,
    "pageNumber": 1,
    "totalItems": 2,
    "contents": [{
      "playDuration": 27,
      "stayDuration": 30,
      "param1": "",
      "param2": "",
      "param3": "vod",
      "createdTime": 1635439162000,
      "ipAddress": "116.23.155.239",
      "address": "广东广州",
      "referer": "https://console.polyv.net/live/#/channel/2000007/video-library",
      "browser": "Chrome 9",
      "sessionId": "",
      "province": "广东",
      "city": "广州",
      "ptype": 0,
      "originSessionId": ""
    }, {
      "playDuration": 179,
      "stayDuration": 180,
      "param1": "1634632927097",
      "param2": "直播观众/21234",
      "param3": "live",
      "createdTime": 1634633045000,
      "ipAddress": "61.144.145.78",
      "address": "广东广州",
      "referer": "https://live.polyv.cn/watch/2000007",
      "browser": "Chrome 9",
      "sessionId": "g3ffzv8bkj",
      "province": "广东",
      "city": "广州",
      "ptype": 0,
      "originSessionId": "g3ffzv8bkj"
    }],
    "limit": 2,
    "endRow": 2,
    "totalPages": 1,
    "nextPageNumber": 1,
    "startRow": 1,
    "firstPage": true,
    "lastPage": true,
    "prePageNumber": 1,
    "offset": 0
  }
}

Error Example

{
    "code": 400,
    "status": "error",
    "message": "invalid signature.",
    "data": ""
}
联系客服,在线咨询
在线咨询