Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

调用TRTC的接口时出现region相关的报错 #220

Closed
ccfish86 opened this issue Mar 14, 2024 · 1 comment
Closed

调用TRTC的接口时出现region相关的报错 #220

ccfish86 opened this issue Mar 14, 2024 · 1 comment

Comments

@ccfish86
Copy link

使用的SDK是 'com.tencentcloudapi:tencentcloud-sdk-java-trtc:3.1.971'
初始化client及调用的API的业务代码

    private TrtcClient getClient() {

        if (trtcClient == null) {
            /*
             * 必要步骤: 实例化一个认证对象,入参需要传入腾讯云账户密钥对secretId,secretKey。
             * 这里采用的是从环境变量读取的方式,需要在环境变量中先设置这两个值。 您也可以直接在代码中写死密钥对,但是小心不要将代码复制、上传或者分享给他人,
             * 以免泄露密钥对危及您的财产安全。 SecretId、SecretKey 查询:
             * https://console.cloud.tencent.com/cam/capi
             */
            Credential cred = new Credential(qcloudIMProperty.getSecretId(), qcloudIMProperty.getSecretKey());

            // 实例化一个http选项,可选,没有特殊需求可以跳过
            HttpProfile httpProfile = new HttpProfile();
            /*
             * SDK默认使用POST方法。 如果您一定要使用GET方法,可以在这里设置。GET方法无法处理一些较大的请求
             */
            httpProfile.setReqMethod("POST");
            /*
             * SDK有默认的超时时间,非必要请不要进行调整 如有需要请在代码中查阅以获取最新的默认值
             */
            httpProfile.setConnTimeout(60);

            /*
             * 非必要步骤: 实例化一个客户端配置对象,可以指定超时时间等配置
             */
            ClientProfile clientProfile = new ClientProfile();
            /*
             * SDK默认用TC3-HMAC-SHA256进行签名 非必要请不要修改这个字段
             */
            clientProfile.setSignMethod("HmacSHA256");
            clientProfile.setHttpProfile(httpProfile);
            /*
             * 实例化要请求产品(以sms为例)的client对象 第二个参数是地域信息,可以直接填写字符串ap-guangzhou,支持的地域列表参考
             * https://cloud.tencent.com/document/
             */
            trtcClient = new TrtcClient(cred, qcloudIMProperty.getRegion(), clientProfile);
        }

        return trtcClient;
    }
    public void removeUser(String roomId, String... userIds) {
        if (userIds.length == 0) {
            return;
        }
        var client = getClient();
        var req = new RemoveUserByStrRoomIdRequest();
        req.setSdkAppId(qcloudIMProperty.getAppid());
        req.setRoomId(roomId);
        req.setUserIds(userIds);
        try {
            client.RemoveUserByStrRoomId(req);
        } catch (TencentCloudSDKException e) {
            log.error("移出用户失败", e);
        }
    }

如果初始化client时传region时,报以下错误:
com.tencentcloudapi.common.exception.TencentCloudSDKException: A value specified in X-TC-Region is not valid, is unsupported, or cannot be used.
at com.tencentcloudapi.common.AbstractClient.processResponseJson(AbstractClient.java:470) ~[tencentcloud-sdk-java-common-3.1.971.jar!/:na]
at com.tencentcloudapi.common.AbstractClient.internalRequest(AbstractClient.java:417) ~[tencentcloud-sdk-java-common-3.1.971.jar!/:na]
at com.tencentcloudapi.trtc.v20190722.TrtcClient.RemoveUserByStrRoomId(TrtcClient.java:521) ~[tencentcloud-sdk-java-trtc-3.1.971.jar!/:na]

如果初始化client不传region时,以下错误:
com.tencentcloudapi.common.exception.TencentCloudSDKException: The request is missing a required parameter Region.
at com.tencentcloudapi.common.AbstractClient.processResponseJson(AbstractClient.java:470) ~[tencentcloud-sdk-java-common-3.1.971.jar!/:na]
at com.tencentcloudapi.common.AbstractClient.internalRequest(AbstractClient.java:417) ~[tencentcloud-sdk-java-common-3.1.971.jar!/:na]
at com.tencentcloudapi.trtc.v20190722.TrtcClient.RemoveUserByStrRoomId(TrtcClient.java:521) ~[tencentcloud-sdk-java-trtc-3.1.971.jar!/:na]
at com.gavin.qcloud.api.impl.QcloudTrtcComponentImpl.removeUser(QcloudTrtcComponentImpl.java:114) ~[witness-common-im-2.0.0-plain.jar!/:na]

@ccfish86
Copy link
Author

更新3.1.978 后已无此问题。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant