本文介绍使用Java SDK从指定分组中删除个体的示例代码。
功能描述
删除分组中个体不会删除个体对应的信息以及图片,只是解除个体与该分组的绑定关系。具体参数说明请参考删除分组中个体API接口描述文档。
准备工作
在进行具体的服务调用之前,请参见以下步骤,完成准备工作:
- 创建阿里云AccessKeyId和AccessKeySecret。具体请参见创建AccessKey。
- 安装Java依赖。具体请参见安装Java依赖。
- 如果使用本地文件或者二进制文件检测,请下载并在项目工程中引入Extension.Uploader工具类。
从指定分组删除个体代码示例
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;
/**
* 将个体从指定组中移除
*
* @author wangxuan
* @date 2018/06/25
*/
public class FaceDeleteGroupsRequestSample {
public static void main(String[] args) throws Exception {
//请替换成您自己的accessKeyId、accessKeySecret
IClientProfile profile = DefaultProfile.getProfile("cn-shanghai", "您自己的accessId", "您自己的accessSecret");
DefaultProfile.addEndpoint("cn-shanghai", "cn-shanghai", "Green", "green.cn-shanghai.aliyuncs.com");
IAcsClient client = new DefaultAcsClient(profile);
DeleteGroupsRequest request = new DeleteGroupsRequest();
request.setAcceptFormat(FormatType.JSON); // 指定api返回格式
request.setMethod(com.aliyuncs.http.MethodType.POST); // 指定请求方法
request.setEncoding("utf-8");
JSONObject data = new JSONObject();
/**
* personId: 用户自定义个体Id,必填
* groupIds: 用户自定义组Id列表,必填
*/
data.put("personId", "personId_test_3");
data.put("groupIds", Arrays.asList("groupId_1"));
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();
}
}
}
在文档使用中是否遇到以下问题
更多建议
匿名提交