Query a list of groups
Updated at:
Use the Content Moderation Go SDK to retrieve the IDs of all person groups in your account.
Prerequisites
Before you begin, ensure that you have:
Go dependencies installed. See Installation for the required Go version. Using a different version causes API call failures.
The Content Moderation API endpoint configured. See Endpoints.
Query all person group IDs
The following example calls GetGroups to retrieve the IDs of all person groups.
package main
import (
"fmt"
"os"
"strconv"
"github.com/aliyun/alibaba-cloud-sdk-go/services/green"
)
func main() {
// Reuse the client across requests to improve performance and avoid repeated connections.
// Load credentials from environment variables to keep them out of your code.
client, err := green.NewClientWithAccessKey(
"cn-shanghai",
os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"),
os.Getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"),
)
if err != nil {
fmt.Println(err.Error())
return
}
request := green.CreateGetGroupsRequest()
response, err := client.GetGroups(request)
if err != nil {
fmt.Println(err.Error())
return
}
if response.GetHttpStatus() != 200 {
fmt.Println("Request failed. HTTP status code: " + strconv.Itoa(response.GetHttpStatus()))
return
}
fmt.Println(response.GetHttpContentString())
}Set the following environment variables before running the example:
| Environment variable | Description |
|---|---|
ALIBABA_CLOUD_ACCESS_KEY_ID | The AccessKey ID of your RAM user |
ALIBABA_CLOUD_ACCESS_KEY_SECRET | The AccessKey secret of your RAM user |
For the full response schema and parameter descriptions, see GetGroups.
Is this page helpful?