Search in sources :

Example 21 with Credential

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());
    }
}
Also used : Credential(com.tencentcloudapi.common.Credential) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) ClientProfile(com.tencentcloudapi.common.profile.ClientProfile) Keyword(com.tencentcloudapi.soe.v20180724.models.Keyword) KeywordEvaluateRequest(com.tencentcloudapi.soe.v20180724.models.KeywordEvaluateRequest) HttpProfile(com.tencentcloudapi.common.profile.HttpProfile) SoeClient(com.tencentcloudapi.soe.v20180724.SoeClient) IOException(java.io.IOException) KeywordEvaluateResponse(com.tencentcloudapi.soe.v20180724.models.KeywordEvaluateResponse)

Example 22 with Credential

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());
    }
}
Also used : Credential(com.tencentcloudapi.common.Credential) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) CommonClient(com.tencentcloudapi.common.CommonClient)

Example 23 with Credential

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());
    }
}
Also used : Credential(com.tencentcloudapi.common.Credential) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) HashMap(java.util.HashMap) CommonClient(com.tencentcloudapi.common.CommonClient)

Example 24 with Credential

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());
    }
}
Also used : Credential(com.tencentcloudapi.common.Credential) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) DescribeInstancesRequest(com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesRequest) CommonClient(com.tencentcloudapi.common.CommonClient)

Example 25 with Credential

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());
    }
}
Also used : Credential(com.tencentcloudapi.common.Credential) TencentCloudSDKException(com.tencentcloudapi.common.exception.TencentCloudSDKException) CvmClient(com.tencentcloudapi.cvm.v20170312.CvmClient) DescribeInstancesRequest(com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesRequest) DescribeInstancesResponse(com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesResponse)

Aggregations

Credential (com.tencentcloudapi.common.Credential)55 TencentCloudSDKException (com.tencentcloudapi.common.exception.TencentCloudSDKException)41 ClientProfile (com.tencentcloudapi.common.profile.ClientProfile)39 HttpProfile (com.tencentcloudapi.common.profile.HttpProfile)39 CvmClient (com.tencentcloudapi.cvm.v20170312.CvmClient)12 DescribeInstancesRequest (com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesRequest)12 DescribeInstancesResponse (com.tencentcloudapi.cvm.v20170312.models.DescribeInstancesResponse)10 CommonClient (com.tencentcloudapi.common.CommonClient)9 Test (org.junit.Test)8 TciClient (com.tencentcloudapi.tci.v20190318.TciClient)6 SoeClient (com.tencentcloudapi.soe.v20180724.SoeClient)5 OcrClient (com.tencentcloudapi.ocr.v20181119.OcrClient)3 SmsClient (com.tencentcloudapi.sms.v20210111.SmsClient)3 HashMap (java.util.HashMap)3 CmqConfig (com.qcloud.cmq.entity.CmqConfig)2 DescribeZonesRequest (com.tencentcloudapi.cvm.v20170312.models.DescribeZonesRequest)2 DescribeZonesResponse (com.tencentcloudapi.cvm.v20170312.models.DescribeZonesResponse)2 Filter (com.tencentcloudapi.cvm.v20170312.models.Filter)2 EccClient (com.tencentcloudapi.ecc.v20181213.EccClient)2 SendSmsRequest (com.tencentcloudapi.sms.v20210111.models.SendSmsRequest)2