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
Help Center/
Content Moderation/
SDK Reference/
Using the .NET SDK/
SDK Calling Example/
Moderation (Text)/
Text Moderation (V2)
Copied.
Text Moderation (V2)
- This section describes how to use the Text Moderation SDK by AK/SK authentication.
Replace the AK/SK in the sample code with the actual AK/SK. Set text in TextDetectionItemsReq in the code to configure the text to be detected, and execute the code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
using System; using System.Collections.Generic; using HuaweiCloud.SDK.Core; using HuaweiCloud.SDK.Core.Auth; using HuaweiCloud.SDK.Moderation; using HuaweiCloud.SDK.Moderation.V2; using HuaweiCloud.SDK.Moderation.V2.Model; namespace RunTextModerationSolution { class Program { static void Main(string[] args) { //Enter your AK/SK. const string ak = "<YOUR AK>"; const string sk = "<YOUR SK>"; var config = HttpConfig.GetDefaultConfig(); config.IgnoreSslVerification = true; var auth = new BasicCredentials(ak, sk); var client = ModerationClient.NewBuilder() .WithCredential(auth) .WithRegion(ModerationRegion.ValueOf("xxx")) //Replace xxx with the region where the service is located. .WithHttpConfig(config) .Build(); var req = new RunTextModerationRequest { }; List<TextDetectionItemsReq> listTextDetectionItemsReqItems = new List<TextDetectionItemsReq>(); listTextDetectionItemsReqItems.Add(new TextDetectionItemsReq() { Text = "text", //Enter the text to be detected. Type = "content" }); List<String> listTextDetectionReqCategories = new List<String>(); listTextDetectionReqCategories.Add("porn"); listTextDetectionReqCategories.Add("abuse"); listTextDetectionReqCategories.Add("contraband"); listTextDetectionReqCategories.Add("flood"); req.Body = new TextDetectionReq() { Items = listTextDetectionItemsReqItems, Categories = listTextDetectionReqCategories }; try { var resp = client.RunTextModeration(req); var respStatusCode = resp.HttpStatusCode; Console.WriteLine(respStatusCode); Console.WriteLine(JsonConvert.DeserializeObject(resp.HttpBody)); } catch (RequestTimeoutException requestTimeoutException) { Console.WriteLine(requestTimeoutException.ErrorMessage); } catch (ServiceResponseException clientRequestException) { Console.WriteLine(clientRequestException.HttpStatusCode); Console.WriteLine(clientRequestException.ErrorCode); Console.WriteLine(clientRequestException.ErrorMsg); } catch (ConnectionException connectionException) { Console.WriteLine(connectionException.ErrorMessage); } } } }
- If 200 is displayed on the console, the code is successfully executed. The text moderation result is displayed on the console.
200 {'result': {'detail': {'contraband': ['potassium arsenite'], 'porn': ['nude chat']}, 'suggestion': 'block'}}
Parent topic: Moderation (Text)
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