更新时间:2023-11-20 GMT+08:00
文本内容审核(V3)
- Python3语言请求代码示例
# encoding:utf-8 import requests import base64 url = "https://{endpoint}/v3/{project_id}/moderation/text" token = "用户获取得到的实际token值" 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)
- Java语言请求代码示例
//使用前请添加如下依赖(版本可自行更新,此处只是示例): <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; /** * 此demo仅供测试使用,强烈建议使用SDK * 使用前请添加上方的okhttp3依赖 */ 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", "用户获取得到的实际token值") .build(); Response response = client.newCall(request).execute(); String string = response.body().string(); System.out.println(string); } catch (Exception e) { e.printStackTrace(); } } }
- PHP语言请求代码示例
<?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: 用户获取得到的实际token值', 'Content-Type: application/json' ), )); $response = curl_exec($curl); curl_close($curl); echo $response;
父主题: 应用示例