Delete a person from a group

Updated at:

Use the Java SDK to remove a person from one or more custom groups in Content Moderation.

This operation unbinds the person from the specified groups. It does not delete the person's profile or associated images.

Prerequisites

Before you begin, ensure that you have:

  • Java dependencies installed using the Java version specified in the Installation guide. Using a different Java version causes API calls to fail.

  • The personId of the person to remove and the groupIds of the target groups.

  • (Optional) The Extension.Uploader utility class downloaded and imported into your project, if you submit local images or binary image streams for image moderation.

For available endpoints, see Endpoints. For the full API reference, see Delete a person from a group.

Remove a person from a group

The following example removes a person from a specified group. Replace personId_test_3 with the target person's ID and groupId_1 with the ID of the group to remove the person from. To remove the person from multiple groups, add additional group IDs to the groupIds list.

Request parameters

ParameterTypeRequiredDescription
personIdStringYesThe ID of the person to remove
groupIdsList\<String\>YesThe IDs of the groups to remove the person from
import java.util.Arrays;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.green.model.v20180509.DeleteGroupsRequest;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.http.HttpResponse;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;

public class FaceDeleteGroupsRequestSample {

    public static void main(String[] args) throws Exception {
        // Use a RAM user's AccessKey pair instead of your Alibaba Cloud account credentials.
        // Load credentials from environment variables to avoid hardcoding sensitive information.
        DefaultProfile profile = DefaultProfile.getProfile(
                "cn-shanghai",
                System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
                System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        DefaultProfile.addEndpoint("cn-shanghai", "Green", "green.cn-shanghai.aliyuncs.com");

        // Reuse the client instance across requests to improve performance
        // and avoid repeated connection overhead.
        IAcsClient client = new DefaultAcsClient(profile);

        DeleteGroupsRequest request = new DeleteGroupsRequest();
        request.setAcceptFormat(FormatType.JSON);
        request.setMethod(com.aliyuncs.http.MethodType.POST);
        request.setEncoding("utf-8");

        JSONObject data = new JSONObject();
        data.put("personId", "personId_test_3");   // Replace with the target person's ID
        data.put("groupIds", Arrays.asList("groupId_1"));  // Replace with the target group ID(s)

        request.setHttpContent(data.toJSONString().getBytes("UTF-8"), "UTF-8", FormatType.JSON);
        request.setConnectTimeout(3000);
        request.setReadTimeout(6000);

        try {
            HttpResponse httpResponse = client.doAction(request);

            if (httpResponse.isSuccess()) {
                JSONObject scrResponse = JSON.parseObject(new String(httpResponse.getHttpContent(), "UTF-8"));
                System.out.println(JSON.toJSONString(scrResponse, true));
                if (200 == scrResponse.getInteger("code")) {
                    JSONObject resultObject = scrResponse.getJSONObject("data");
                    if (200 == resultObject.getInteger("code")) {
                        System.out.println(resultObject.getString("personId"));
                    } else {
                        System.out.println("task process fail:" + resultObject.getInteger("code"));
                    }
                } else {
                    System.out.println("detect not success. code:" + scrResponse.getInteger("code"));
                }
            } else {
                System.out.println("response not success. status:" + httpResponse.getStatus());
            }
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Response

A successful response returns HTTP 200 with a JSON body. The outer code field indicates the API-level result. When code is 200, check the data object for the operation result.

{
    "code": 200,
    "data": {
        "code": 200,
        "personId": "personId_test_3"
    }
}

What's next