文档首页 > > API参考> 人脸识别API(V1)>

查询服务状态

查询服务状态

分享
更新时间:2021/05/28 GMT+08:00

功能介绍

用于查询服务的开通状态。

前提条件:

请确保您已开通人脸识别服务,具体操作方法请参见申请服务

调试

您可以在API Explorer中调试该接口。

URI

GET /v1/{project_id}/subscribe

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

项目ID,获取方法请参见获取项目ID/账号名/AK/SK

请求参数

表2 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

用户Token。

Token认证就是在调用API的时候将Token加到请求消息头,从而通过身份认证,获得操作API的权限,响应消息头中X-Subject-Token的值即为Token。

响应参数

状态码:200

表3 响应Body参数

参数名

参数类型

说明

max_face_set_number

Integer

调用成功时表示最大的人脸库数量。

调用失败时无此字段。

detect_service

Object

调用成功时表示该子服务信息,ServiceInfo结构详见ServiceInfo

调用失败时无此字段。

compare_service

Object

调用成功时表示该子服务信息,ServiceInfo结构详见表4

调用失败时无此字段。

live_detect_service

Object

调用成功时表示该子服务信息,ServiceInfo结构详见表4

调用失败时无此字段。

search_service

Object

调用成功时表示该子服务信息,ServiceInfo结构详见表4

调用失败时无此字段。

error_code

String

调用失败时的错误码,具体请参考错误码

调用成功时无此字段。

error_msg

String

调用失败时的错误信息。

调用成功时无此字段。

表4 ServiceInfo

参数

参数类型

描述

subscribe_status

Boolean

是否开通该子服务。

create_time

String

开通该子服务时间。

请求示例

X-Auth-Token值获取方法请参见认证鉴权

  • 请求样例
    GET https://{endpoint}/v1/{project_id}/subscribe
    Request Header:
    Content-Type: application/json
    X-Auth-Token: MIINRwYJKoZIhvcNAQcCoIINODCCDTQCAQExDT...
  • Python3语言请求代码示例(其他语言参照下列示例编写或使用FRS SDK)
    # -*- coding:utf-8 -*-
    import requests
    
    endpoint = '开通服务所在region的人脸识别服务域名'
    project_id = '开通服务所在region的用户项目ID'
    token = '用户获取得到的实际token值'
    
    url = "https://{endpoint}/v1/{project_id}/subscribe".format(endpoint=endpoint, project_id=project_id)
    token = "用户获取得到的实际token值"
    headers = {'Content-Type': 'application/json', 'X-Auth-Token': token}
    
    response = requests.get(url, headers=headers, verify=False)
    print(response.text)
  • Java语言请求代码示例(其他语言参照下列示例编写或使用FRS SDK)
    import com.huawei.trace.http.apache.httpclient.TraceApacheHttpClientBuilder;
    import org.apache.http.HttpEntity;
    import org.apache.http.HttpHeaders;
    import org.apache.http.HttpResponse;
    import org.apache.http.client.config.RequestConfig;
    import org.apache.http.client.methods.HttpGet;
    import org.apache.http.config.Registry;
    import org.apache.http.config.RegistryBuilder;
    import org.apache.http.conn.socket.ConnectionSocketFactory;
    import org.apache.http.conn.socket.PlainConnectionSocketFactory;
    import org.apache.http.conn.ssl.NoopHostnameVerifier;
    import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
    import org.apache.http.impl.client.CloseableHttpClient;
    import org.apache.http.impl.client.HttpClientBuilder;
    import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
    import org.apache.http.ssl.SSLContextBuilder;
    import org.apache.http.ssl.TrustStrategy;
    import org.apache.http.util.EntityUtils;
    import java.io.IOException;
    import java.nio.charset.StandardCharsets;
    import java.security.KeyManagementException;
    import java.security.KeyStoreException;
    import java.security.NoSuchAlgorithmException;
    import java.security.cert.CertificateException;
    import java.security.cert.X509Certificate;
    import java.util.concurrent.TimeUnit;
    import javax.net.ssl.HostnameVerifier;
    import javax.net.ssl.SSLContext;
    
    /**
     * 此demo仅供测试使用,强烈建议使用SDK
     * 使用前需已配置HttpClient jar包。jar包可通过下载SDK获取
     */
    
    public class GetSubscribe {
        protected static HttpClientBuilder buildClient(HttpClientBuilder httpClientBuilder) {
            SSLContext sslContext = null;
            try {
                sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
                    public boolean isTrusted(X509Certificate[] arg0, String arg1) throws CertificateException {
                        return true;
                    }
                }).build();
            } catch (NoSuchAlgorithmException e) {
                throw new RuntimeException(e.getMessage());
            } catch (KeyManagementException e) {
                throw new RuntimeException(e.getMessage());
            } catch (KeyStoreException e) {
                throw new RuntimeException(e.getMessage());
            }
            httpClientBuilder.setSSLContext(sslContext);
            httpClientBuilder.setConnectionTimeToLive(30, TimeUnit.SECONDS);
            HostnameVerifier hostnameVerifier = NoopHostnameVerifier.INSTANCE;
            SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
            Registry<ConnectionSocketFactory> socketFactoryRegistry
                = RegistryBuilder.<ConnectionSocketFactory>create().register("http",
                PlainConnectionSocketFactory.getSocketFactory()).register("https", sslSocketFactory).build();
            PoolingHttpClientConnectionManager connMgr = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
            connMgr.setMaxTotal(200);
            connMgr.setDefaultMaxPerRoute(100);
            httpClientBuilder.setConnectionManager(connMgr);
            return httpClientBuilder;
        }
    
        public static String doGet(String url, String token, CloseableHttpClient client) {
            HttpGet get = new HttpGet(url);
            get.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");
            //time unit is milliseconds
            RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(3000).setSocketTimeout(3000).build();
            get.setConfig(requestConfig);
            get.setHeader("X-Auth-Token", token);
            HttpResponse response = null;
            String result = "";
            try {
                response = client.execute(get);
                HttpEntity responseBody = response.getEntity();
                if (responseBody == null) {
                    System.out.println("the response body is null.");
                    return result;
                } else {
                    byte[] byteStream = EntityUtils.toByteArray(responseBody);
                    System.arraycopy(byteStream, 0, new byte[byteStream.length], 0, byteStream.length);
                    result = new String(byteStream, StandardCharsets.UTF_8);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            return result;
        }
    
        public static void main(String[] args) {
            CloseableHttpClient client = buildClient(TraceApacheHttpClientBuilder.create()).build();
            // endpoint和projectId需要替换成实际信息。
            String url = "https://{{endpoint}}/v1/{{project_id}}/subscribe";
            String token = "对应region的token";
            String result = doGet(url, token, client);
            System.out.println(result);
        }
    }

响应示例

状态码:200

成功响应示例
{
  "max_face_set_number": 10,
   "detect_service": {
        "subscribe_status": true,
        "create_time": "2018-09-03 08:16:48"
   },
   "compare_service": {
        "subscribe_status": true,
        "create_time": "2018-09-03 08:16:48"
   },
   "search_service": {
        "subscribe_status": true,
        "create_time": "2018-09-03 08:16:48"
   },
   "live_detect_service": {
        "subscribe_status": true,
        "create_time": "2018-09-03 08:16:48"
   }
}

状态码:400

失败响应样例
{
  "error_code": "FRS.0019",
  "error_msg": "The service has not been subscribed."
}

状态码

状态码请参见状态码

错误码

错误码请参见错误码

分享:

    相关文档

    相关产品