Help Center/ Face Recognition Service/ Getting Started/ Calling APIs for Face Detection
Updated on 2022-07-28 GMT+08:00

Calling APIs for Face Detection

This section describes how to call Face Detection APIs of FRS to help you get familiar with FRS.

To call an FRS API, there are four steps:

Step 1: Subscribe to the Service

Step 2: Configure the Environment

Step 3: Use a Token for Authentication

Step 4: Call the Service

Preparations

You have registered an account with HUAWEI CLOUD. Your account cannot be in arrears or frozen.

Step 1: Subscribe to the Service

  1. Log in to the FRS console.
  2. Click Authorization in the navigation pane on the left to authorize FRS to access data stored on OBS.
  3. Select and subscribe to your desired APIs.

    In this example, subscribe to the Face Detection API.

Step 2: Configure the Environment

Download and install Postman 7.24.0.

Step 3: Use a Token for Authentication

  1. On the Postman page, choose New > Collection, set the name, and click Create.

  2. Right-click the created collection and choose Add Request from the shortcut menu. Set the request name and click Save.

  3. Change the request mode to POST and enter the URL.

    For example, if ap-southeast-1 is used, the URL is https://iam.ap-southeast-1.myhuaweicloud.com/v3/auth/tokens.

  4. In the Headers list, set KEY to Content-Type and VALUE to application/json.

  5. Click the Body configuration item, select raw, and enter the following code in the blank area.

    Replace username, domainname, ******** (login password), and name (region where the service is deployed) with the actual values. To obtain the values of these parameters, log in to the management console and click My Credentials.

    The region where FRS is deployed must be the same as the region where the called service is located. In this example, the region is ap-southeast-1.

    {
        "auth": {
            "identity": {
                "methods": [
                    "password"
                ],
                "password": {
                    "user": {
                        "name": "username",
                        "password": "**********",
                        "domain": {
                            "name": "domainname"
                        }
                    }
                }
            },
            "scope": {
                "project": {
                    "name": "ap-southeast-1"
                }
            }
        }
    }
  6. Click Send in the upper right corner to send the request. Obtain the token value from the returned result. The token is valid for 24 hours.

Step 4: Send API Calling Requests

  1. Create a request, set the request mode to POST, and enter the URL as required.

    For example, if the Face Detection subservice is deployed in the CN-Hong Kong region, the request URL is https://face.ap-southeast-1.myhuaweicloud.com/v2/{project_id}/face-detect.

    Click Headers and copy the token value to X-Auth-Token.

    Log in to the My Credential page, query the ID of the project in the CN-Hong Kong region, and replace {project_id} in the URI with the queried project ID.

  2. Click Body and enter the Base64 code of the image to the request body. For details about the APIs, see Face Detection.
    {     
         "image":"/9j/4AAQSkZJRgABAgEASABIAAD/4RFZRXhpZgAATU0AKgAAAA..." 
    }
  3. Click Send in the upper right corner to send the request and view the results.