use of com.tencentcloudapi.common.Credential in project tencentcloud-sdk-java by TencentCloud.
the class KeywordEvaluate method main.
public static void main(String[] args) throws IOException {
try {
Credential cred = new Credential("", "");
HttpProfile httpProfile = new HttpProfile();
httpProfile.setEndpoint("soe.tencentcloudapi.com");
ClientProfile clientProfile = new ClientProfile();
clientProfile.setHttpProfile(httpProfile);
SoeClient client = new SoeClient(cred, "", clientProfile);
KeywordEvaluateRequest req = new KeywordEvaluateRequest();
req.setSeqId(1);
req.setIsEnd(1);
req.setVoiceFileType(3);
req.setVoiceEncodeType(1);
req.setSessionId("test_12345_456");
byte[] buf = Files.readAllBytes(Paths.get(AUDIO_FOR_ONCE));
String base64Str = new sun.misc.BASE64Encoder().encode(buf);
req.setUserVoiceData(base64Str);
Keyword[] keywords1 = new Keyword[2];
Keyword keyword1 = new Keyword();
keyword1.setRefText("bike");
keyword1.setEvalMode(0);
keyword1.setServerType(0);
keyword1.setScoreCoeff(1.0f);
keyword1.setTextMode(0);
keywords1[0] = keyword1;
Keyword keyword2 = new Keyword();
keyword2.setRefText("bick");
keyword2.setEvalMode(0);
keyword2.setServerType(0);
keyword2.setScoreCoeff(1.0f);
keyword2.setTextMode(0);
keywords1[1] = keyword2;
req.setKeywords(keywords1);
KeywordEvaluateResponse resp = client.KeywordEvaluate(req);
System.out.println(KeywordEvaluateResponse.toJsonString(resp));
} catch (TencentCloudSDKException | IOException e) {
System.out.println(e.toString());
}
}
use of com.tencentcloudapi.common.Credential in project tencentcloud-sdk-java by TencentCloud.
the class CommonClientCall method main.
public static void main(String[] args) {
try {
// 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey
Credential cred = new Credential("secretId", "secretKey");
// 实例化要请求产品的CommonClient对象,依次传入产品名、产品版本、Credential、地域
CommonClient client = new CommonClient("cvm", "2017-03-12", cred, "ap-guangzhou");
/* 调用client对象的call方法,传入接口名和json格式的字符串向接口发起调用
* 以查询可用区(zone)为广州一区,实例计费模式(instance-charge-type)为包年包月或者按量计费的实例为例
*/
String resp = client.call("DescribeInstances", "{\"Filters\":" + "[{\"Name\":\"zone\"," + "\"Values\":[\"ap-guangzhou-1\"]}," + "{\"Name\":\"instance-charge-type\"," + "\"Values\":[\"PREPAID\",\"POSTPAID_BY_HOUR\"]}]" + "}");
// 输出返回的字符串结果
System.out.println(resp);
} catch (TencentCloudSDKException e) {
System.out.println(e.toString());
}
}
use of com.tencentcloudapi.common.Credential in project tencentcloud-sdk-java by TencentCloud.
the class CommonClientCallOctetStream method main.
public static void main(String[] args) {
try {
// 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey
Credential cred = new Credential("secretId", "secretKey");
// 实例化要请求产品的CommonClient对象,依次传入产品名、产品版本、Credential、地域
CommonClient client = new CommonClient("cls", "2020-10-16", cred, "ap-guangzhou");
// 调用client对象的call方法,传入接口名、请求入参(http头部)和二进制包体向接口发起调用
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("X-CLS-TopicId", "e621fdb8-16f4-41cf-bc73-5aead0b75a03");
headers.put("X-CLS-HashKey", "0fffffffffffffffffffffffffffffff");
headers.put("X-CLS-CompressType", "");
// 实际内容可能需要从外部文件加载
byte[] body = new byte[1024];
String resp = client.callOctetStream("UploadLog", headers, body);
// 输出返回的字符串结果
System.out.println(resp);
} catch (TencentCloudSDKException e) {
System.out.println(e.toString());
}
}
use of com.tencentcloudapi.common.Credential in project tencentcloud-sdk-java by TencentCloud.
the class CommonClientRequest method main.
public static void main(String[] args) {
try {
// 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey
Credential cred = new Credential("secretId", "secretKey");
// 实例化要请求产品的CommonClient对象,依次传入产品名、产品版本、Credential、地域
CommonClient client = new CommonClient("cvm", "2017-03-12", cred, "ap-guangzhou");
/* CommonClient中的commonRequest方法支持传入继承了AbstractModel的Request类和接口名对接口进行调用
* 用户可以按照标准自行实现一个继承了AbstractModel的Request类
*/
DescribeInstancesRequest req = new DescribeInstancesRequest();
String resp = client.commonRequest(req, "DescribeInstances");
// 输出返回的字符串结果
System.out.println(resp);
} catch (TencentCloudSDKException e) {
System.out.println(e.toString());
}
}
use of com.tencentcloudapi.common.Credential in project tencentcloud-sdk-java by TencentCloud.
the class Retry method main.
public static void main(String[] args) {
try {
// 实例化一个认证对象,入参需要传入腾讯云账户secretId,secretKey
Credential cred = new Credential("secretId", "secretKey");
// 实例化要请求产品(以cvm为例)的client对象,依次传入Credential、地域
CvmClient client = new CvmClient(cred, "ap-guangzhou");
// 实例化一个cvm实例信息查询请求对象,每个接口都会对应一个request对象。
DescribeInstancesRequest req = new DescribeInstancesRequest();
// 通过client对象调用retry方法发起请求。依次传入请求对象req和重试次数
// 注意需要将返回值强制转换成与请求对象对应的Response类型
DescribeInstancesResponse resp = (DescribeInstancesResponse) client.retry(req, 5);
// 输出json格式的字符串回包
System.out.println(DescribeInstancesResponse.toJsonString(resp));
} catch (TencentCloudSDKException e) {
System.out.println(e.toString());
}
}
Aggregations