合作咨询
我们的专家服务团队将竭诚为您提供专业的合作咨询服务
此接口用于查询当前设备的信息。
承载协议 | HTTPS GET |
|---|---|
接口方向 | 开发者服务器 -> 华为服务器 |
接口URL | https://connect-api.cloud.huawei.com/api/publish/v2/device/list |
数据格式 | 请求:Content-Type: application/json 响应:Content-Type: application/json |
本接口支持使用Service Account方式和API客户端方式,区别请参见获取服务端授权。
Service Account方式:
参数名称 | 必选(M)/可选(O) | 类型 | 参数说明 |
|---|---|---|---|
Authorization | M | String | 认证信息,格式为“Authorization: Bearer ${JWT}”。JWT为通过Service Account方式获取授权中获取的鉴权令牌。 |
API客户端方式:
参数名称 | 必选(M)/可选(O) | 类型 | 参数说明 |
|---|---|---|---|
deviceName | O | String(256) | 设备名称。 支持模糊查询。 |
fromRecCount | O | Integer(32) | 起始页数。 取值范围:最小为1 默认值:1 |
maxReqCount | O | Integer(32) | 每页返回条数。 取值范围:[1,100] 默认值:20 |
order | O | Integer(32) | 返回的结果排序方式。 取值范围:
|
- GET /api/publish/v2/device/list?deviceName=testDevice HTTP/1.1
- Host: connect-api.cloud.huawei.com
- client_id: 41******68
- Content-Type: application/json
- Authorization: Bearer ******
参数名称 | 必选(M)/可选(O) | 类型 | 参数说明 |
|---|---|---|---|
ret | M | 包含返回码及描述信息的结果。 | |
totalCount | M | Integer(32) | 总记录条数。 |
deviceList | O | List<DeviceInfo> | 设备详情。 |
- {
- "ret": {
- "code": 0,
- "msg": "success"
- },
- "deviceList": [
- {
- "id": "14***************80",
- "deviceName": "testDevice"
- "udid": "111111111222****************************************333333444444",
- "deviceType": 1,
- "createTime": "2024-06-14 11:55:28.676",
- }
- ],
- "totalCount": 1
- }
Java代码示例如下:
- public static JSONObject getDeviceList(String domain, String clientId, String token, String deviceName) {
- HttpGet get = new HttpGet(domain + "/publish/v2/device/list?deviceName=" + deviceName);
-
- get.setHeader("Authorization", "Bearer " + token);
- get.setHeader("client_id", clientId);
- try {
- CloseableHttpClient httpClient = HttpClients.createDefault();
- CloseableHttpResponse httpResponse = httpClient.execute(get);
- int statusCode = httpResponse.getStatusLine().getStatusCode();
- if (statusCode == HttpStatus.SC_OK) {
- BufferedReader br = new BufferedReader(
- new InputStreamReader(httpResponse.getEntity().getContent(), Consts.UTF_8));
- String result = br.readLine();
-
- return JSON.parseObject(result);
- }
- } catch (Exception ignored) {
-
- }
- return null;
- }