Content Moderation
Content Moderation
- What's New
- Product Bulletin
- Service Overview
- Getting Started
- User Guide
- API Reference
-
SDK Reference
- Introduction to Moderation SDK
- Applying for a Service
- Obtaining Authentication Information
- Preparing the Environment
- Using the SDK (Java)
- Using the Python SDK
- Using the .NET SDK
- Using the Go SDK
-
FAQs
- Service Enabling
-
APIs
- How Do I Use Content Moderation APIs?
- What Should I Do When I Fail to Call a Content Moderation API?
- Can I Directly Upload a Word File for Text Moderation?
- What Are the Constraints on Concurrent API Calls?
- What Can I Do if the Request for Calling an API Times Out?
- How Do I Customize a Detection in Text Moderation?
- Can Content Moderation Traverse and Review the Content in an OBS Folder?
- Error Codes
- Monitoring
- Others
- Price Details
- Glossary
- General Reference
On this page
Show all
Copied.
Text Moderation (V3)
- Sample code for a Python 3 request
# encoding:utf-8 import requests import base64 url = "https://{endpoint}/v3/{project_id}/moderation/text" token = "Actual token value obtained by the user" headers = {'Content-Type': 'application/json', 'X-Auth-Token': token} data= { "event_type": "comment", "data": { "text": "test" } } response = requests.post(url, headers=headers, json=data, verify=False) print(response.text)
- Sample code for a Java request
//Add the following dependency before use. (The version is only an example.) <dependency> <groupId>com.squareup.okhttp3</groupId> <artifactId>okhttp</artifactId> <version>3.14.7</version> </dependency> package com.huawei.ais.demo; import java.io.IOException; import okhttp3.MediaType; import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; /** * This demo is used only for tests. You are advised to use the SDK. * Add the okhttp3 dependency before use. */ public class TextModerationDemo { public static void main(String[] args) throws IOException { try { OkHttpClient client = new OkHttpClient().newBuilder() .build(); MediaType mediaType = MediaType.parse("application/json"); RequestBody body = RequestBody.create(mediaType, "{\"event_type\":\"comment\",\"glossary_names\":[],\"data\":{\"text\":\"test\"}}"); Request request = new Request.Builder() .url("https://{endpoint}/v3/{project_id}/moderation/text") .method("POST", body) .header("X-Auth-Token", "Actual token value obtained by the user") .build(); Response response = client.newCall(request).execute(); String string = response.body().string(); System.out.println(string); } catch (Exception e) { e.printStackTrace(); } } }
- Sample code for a PHP request
<?php $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://{endpoint}/v3/{project_id}/moderation/text', CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => '', CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => '{ "event_type": "comment", "data": { "text": "test" } }', CURLOPT_HTTPHEADER => array( 'X-Auth-Token: Actual token value obtained by the user', 'Content-Type: application/json' ), )); $response = curl_exec($curl); curl_close($curl); echo $response;
Table 1 Parameter description Parameter
Description
url
API request URL, for example, https://{endpoint}/v3/{project_id}/moderation/text.
endpoint indicates the endpoint, and project_id indicates the project ID.
token
A token is a user's access credential, which includes user identities and permissions. When you call an API to access a cloud service, a token is required for identity authentication.
For details about how to obtain the token, see Authentication.
Parent topic: Application Examples
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
The system is busy. Please try again later.
For any further questions, feel free to contact us through the chatbot.
Chatbot