API | Operation | Description |
Submitting a text moderation job | Submits a text moderation job. | |
Querying the text moderation job result | Queries the result of the specified text moderation job. |
// Bucket name in the format of BucketName-APPIDString bucket = "examplebucket-1250000000";// Object key, i.e., the full path of a COS object. If the object is in a directory, the path should be "dir1/object1".String cosPath = "dir1/exampleobject.txt";// URL of the text. Either `Object` or `Url` can be selected at a time.String url = "https://myqcloud.com/%205text.txt";// When the input content is plain text, it needs to be Base64-encoded first. The length of the original text before encoding cannot exceed 10,000 UTF-8 characters. If the length limit is exceeded, the API will report an error.String content = Base64.encodeToString("Test text".getBytes(Charset.forName("UTF-8")), Base64.NO_WRAP);PostTextAuditRequest request = new PostTextAuditRequest(bucket);request.setObject(cosPath);request.setUrl(url);request.setContent(content);// Set the original content, which can contain up to 512 bytes. This field will be returned in the response as-is.request.setDataId("DataId");// Callback address, which must start with `http://` or `https://`.request.setCallback("https://github.com");// Structure of the callback content. Valid values: `Simple` (the callback content contains basic information), `Detail` (the callback content contains detailed information). Default value: `Simple`.request.setCallbackVersion("Detail");// The scene to be moderated, such as `Porn` (pornography) and `Ads` (advertising). You can pass in multiple types and separate them by comma, such as `Porn,Ads`.request.setDetectType("Porn,Ads");// `CIService` is a subclass of `CosXmlService` and has the same initialization method as it.ciService.postTextAuditAsync(request, new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult cosResult) {// `result` is the result of the submitted text moderation job.// For detailed fields, see the API documentation or SDK source code.TextAuditResult result = (TextAuditResult) cosResult;}@Overridepublic void onFail(CosXmlRequest request, CosXmlClientException clientException, CosXmlServiceException serviceException) {if (clientException != null) {clientException.printStackTrace();} else {serviceException.printStackTrace();}}});
// Bucket name in the format of BucketName-APPIDString bucket = "examplebucket-1250000000";// Moderation job IDString jobId = "iab1ca9fc8a3ed11ea834c525400863904";GetTextAuditRequest request = new GetTextAuditRequest(bucket, jobId);// `CIService` is a subclass of `CosXmlService` and has the same initialization method as it.ciService.getTextAuditAsync(request, new CosXmlResultListener() {@Overridepublic void onSuccess(CosXmlRequest request, CosXmlResult cosResult) {// `result` is the result of the text moderation job.// For detailed fields, see the API documentation or SDK source code.TextAuditResult result = (TextAuditResult) cosResult;}@Overridepublic void onFail(CosXmlRequest request, CosXmlClientException clientException, CosXmlServiceException serviceException) {if (clientException != null) {clientException.printStackTrace();} else {serviceException.printStackTrace();}}});
Was this page helpful?