Help Center> Live> API Reference> Streams Management APIs> Querying the Number of Online Viewers

Querying the Number of Online Viewers

Function

This API is used to query the number of online viewers.

URI

GET /v1/{project_id}/stream/users

Table 1 Path parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID. For details about how to obtain a project ID, see "Obtaining a Project ID" .

Table 2 Query parameters

Parameter

Mandatory

Type

Description

domain

Yes

String

Streaming domain name

app_name

No

String

Application name.

stream_name

No

String

Stream name

start_time

No

String

Start time in the format of yyyy-MM-ddThh:mm:ssZ (UTC time) If the start time is not specified, the number of online viewers in the last statistical period is queried.

end_time

No

String

End time in the format of yyyy-MM-ddTHH:mm:ssZ (UTC time).

  • If neither start_time nor end_time is set, the server queries data over the past statistical period.

  • If start_time is set but end_time is not, the current time is used as end_time.

  • If end_time is set but start_time is not, the request is invalid. You can query data over the past three months.

  • The time span between start_time and end_time cannot be greater than 30 days.

step

No

Integer

Statistical period

Unit: minute

Request Parameters

Table 3 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

User token.

The token is obtained by calling the IAM API used to obtain a user token. The token is the value of X-Subject-Token in the response header.

Response Parameters

Status code: 200

Table 4 Response body parameters

Parameter

Type

Description

total

Integer

Total number of elements in the query result

user_info

Array of UserInfo objects

Audio and video information that is being pushed

Table 5 UserInfo

Parameter

Type

Description

user_num

Integer

Number of online viewers

timestamp

String

Push time in the format of yyyy-MM-ddTHH:mm:ssZ (UTC time)

Status code: 400

Table 6 Response body parameters

Parameter

Type

Description

error_code

String

Error Code

error_msg

String

Error description

Example Requests

GET https://{endpoint}/v1/{project_id}/stream/users?domain=play.example.huawei.com&app_name=live&stream_name=xxx

Example Responses

Status code: 200

Number of online viewers queried successfully.

{
  "total" : 1,
  "user_info" : [ {
    "user_num" : 1024,
    "timestamp" : "2018-05-19T21:10:15Z"
  } ]
}

Status code: 400

Failed to query the number of online viewers.

{
  "error_code" : "LIVE.100011001",
  "error_msg" : "Request Illegal"
}

Status Codes

Status Code

Description

200

Number of online viewers queried successfully.

400

Failed to query the number of online viewers.

Error Codes

See Error Codes.