本文主要介绍如何通过API删除热词词表。
示例代码
#!/usr/bin/env python
#coding=utf-8
import os
import json
import datetime
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.request import CommonRequest
from aliyunsdkcore.auth.credentials import AccessKeyCredential
def create_common_request(domain, version, protocolType, method, uri):
request = CommonRequest()
request.set_accept_format('json')
request.set_domain(domain)
request.set_version(version)
request.set_protocol_type(protocolType)
request.set_method(method)
request.set_uri_pattern(uri)
request.add_header('Content-Type', 'application/json')
return request
# TODO 请通过环境变量设置您的 AccessKeyId 和 AccessKeySecret
credentials = AccessKeyCredential(os.environ['ALIBABA_CLOUD_ACCESS_KEY_ID'], os.environ['ALIBABA_CLOUD_ACCESS_KEY_SECRET'])
client = AcsClient(region_id='cn-beijing', credential=credentials)
phraseId = "输入热词词表ID"
request = create_common_request('tingwu.cn-beijing.aliyuncs.com', '2023-09-30', 'https', 'DELETE', '/openapi/tingwu/v2/resources/phrases/{}'.format(phraseId))
response = client.do_action_with_exception(request)
print("response: \n" + json.dumps(json.loads(response), indent=4, ensure_ascii=False))
package com.alibaba.tingwu.client.demo.offlinetask;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.http.FormatType;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.http.ProtocolType;
import com.aliyuncs.profile.DefaultProfile;
import org.junit.Test;
/**
* @author tingwu2023
* @desc 删除热词词表demo。
*/
public class DeleteTranscriptionPhrasesTest {
@Test
public void summitTask() throws ClientException {
String phraseId = "请输入热词词表ID";
CommonRequest request = createCommonRequest("tingwu.cn-beijing.aliyuncs.com", "2023-09-30", ProtocolType.HTTPS, MethodType.DELETE, String.format("/openapi/tingwu/v2/resources/phrases/%s", phraseId));
// TODO 请通过环境变量设置您的AccessKeyId、AccessKeySecret
DefaultProfile profile = DefaultProfile.getProfile("cn-beijing", System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"), System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
IAcsClient client = new DefaultAcsClient(profile);
CommonResponse response = client.getCommonResponse(request);
System.out.println(response.getData());
}
public static CommonRequest createCommonRequest(String domain, String version, ProtocolType protocolType, MethodType method, String uri) {
// 创建API请求并设置参数
CommonRequest request = new CommonRequest();
request.setSysDomain(domain);
request.setSysVersion(version);
request.setSysProtocol(protocolType);
request.setSysMethod(method);
request.setSysUriPattern(uri);
request.setHttpContentType(FormatType.JSON);
return request;
}
}
package main
import (
"log"
"os"
"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
)
const (
apiDomain = "tingwu.cn-beijing.aliyuncs.com"
apiVersion = "2023-09-30"
accessKeyEnv = "ALIBABA_CLOUD_ACCESS_KEY_ID"
secretKeyEnv = "ALIBABA_CLOUD_ACCESS_KEY_SECRET"
region = "cn-beijing"
)
func DeleteCommonRequest(phraseId string) *requests.CommonRequest {
request := requests.NewCommonRequest()
request.Method = "DELETE"
request.Domain = apiDomain
request.Version = apiVersion
request.PathPattern = "/openapi/tingwu/v2/resources/phrases/" + phraseId
request.SetContentType("application/json")
request.SetScheme("https")
return request
}
func DeletePhrase() error {
// 请通过环境变量设置您的AccessKeyId、AccessKeySecret
akkey := os.Getenv(accessKeyEnv)
aksecret := os.Getenv(secretKeyEnv)
client, err := sdk.NewClientWithAccessKey(region, akkey, aksecret)
if err != nil {
log.Default().Fatalln(err)
return err
}
//phraseId
phraseId := "输入热词词表ID"
req := DeleteCommonRequest(phraseId)
response, err := client.ProcessCommonRequest(req)
if err != nil {
log.Default().Fatalln(err)
return err
}
log.Default().Println("response body:\n" + string(response.GetHttpContentBytes()))
return nil
}
func main() {
if err := DeletePhrase(); err != nil {
log.Println(err)
}
}
示例输出
{
"Code": "0",
"Data": {
"Status": "SUCCEEDED"
},
"Message": "success",
"RequestId": "A1533F0E-6D00-505D-9B19-C8********"
}
协议解析
具体字段定义如下。
参数名 | 类型 | 说明 |
Status | string | 任务状态 |
RequestId | string | RequestId用于排查问题使用。 |
文档内容是否对您有帮助?