Use the Content Moderation Python SDK to retrieve all person IDs in a specified group.
Prerequisites
Before you begin, ensure that you have:
Python dependencies installed at the required version. See Installation for the required Python version. Using an unsupported version causes subsequent API calls to fail.
The Extension.Uploader utility class downloaded and imported into your project.
Query person IDs in a group
Each person must belong to a group. When you specify a groupId, the API returns all person IDs in that group.
Request parameter
| Parameter | Required | Type | Description |
|---|---|---|---|
groupId | Yes | String | The ID of the group to query. Each person in the system must belong to a group. |
The following example queries all person IDs in the group python_groupId_1.
Note: Reuse the instantiated client across requests to improve performance and avoid repeated connection overhead.
# coding=utf-8
# Query the IDs of the persons in a specified group.
from aliyunsdkcore import client
from aliyunsdkcore.profile import region_provider
from aliyunsdkgreen.request.v20180509 import GetPersonsRequest
import json
# Obtain the AccessKey ID of your RAM user: os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID']
# Obtain the AccessKey secret of your RAM user: os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET']
clt = client.AcsClient("We recommend that you obtain the AccessKey ID of your RAM user from environment variables", "We recommend that you obtain the AccessKey secret of your RAM user from environment variables", "cn-shanghai")
region_provider.modify_point('Green', 'cn-shanghai', 'green.cn-shanghai.aliyuncs.com')
request = GetPersonsRequest.GetPersonsRequest()
request.set_accept_format('JSON')
request.set_content(
bytearray(json.dumps({"groupId": "python_groupId_1"}), "utf-8"))
response = clt.do_action_with_exception(request)
print response
result = json.loads(response)
if 200 == result["code"]:
resultObject = result["data"]
if (200 == resultObject["code"]):
# The status code 200 indicates that person IDs are obtained.
personIds = resultObject["personIds"]
print personIdsResponse structure
A status code of 200 in both result["code"] and result["data"]["code"] indicates success. The personIds field in result["data"] contains the list of person IDs for the group.
| Field | Location | Description |
|---|---|---|
code | result | Top-level status code. 200 indicates the request succeeded. |
code | result["data"] | Operation-level status code. 200 indicates person IDs were retrieved. |
personIds | result["data"] | List of person IDs in the specified group. |
Call this SDK using a Content Moderation API endpoint. For available endpoints, see Endpoints.