【问题标题】:Download Twilio Recording as an InputStream using Twilio Java Sdk v7.x使用 Twilio Java Sdk v7.x 将 Twilio 录制下载为 InputStream
【发布时间】:2017-05-18 04:18:45
【问题描述】:

我正在将我们当前的 Twilio Java SDK 客户端从 6.x 版升级到 7.x 版。 我遇到的问题之一是检索 InputStream 进行录制。 下面是 6.x 版本的代码示例,我有但找不到在 7.x 版本中检索用于录制的 InputStream 的方法。 (目前为 7.0.0-rc10) 你能指导我做错什么吗?

代码 sn-p 版本 = "6.x"

public InputStream retrieveRecording(String recordingSid) {
    Recording recordingToRetrieve = new Recording(twilioRestClient, recordingSid);
    recordingToRetrieve.setRequestAccountSid("xxxxxxxxx");
    return recordingToRetrieve.getMedia(".mp3");
}

code sn-p version = "7.x"

public InputStream retrieveRecording(String recordingSid) {
    Recording recordingToRetrieve = Recording.fetch("xxxxxxxxx", recordingSid).execute();
    //How do I get the mp3 media as an Input stream ?
}

【问题讨论】:

    标签: java twilio twilio-api


    【解决方案1】:

    不幸的是,此时在 Twilio SDK V7 7.0.0-rc-10 中没有简单的方法来检索 InputStream 进行录制,理想情况下它应该内置在 SDK 中,但与此同时,我是如何解决这个问题的找回下载的问题

     private InputStream retrieveRecording(String accountSid, String authToken, String recordingSid) {
        Twilio.init(accountSid, authToken);
        Recording recordingToRetrieve = Recording.fetch(accountSid, recordingSid).execute();
        String uri = recordingToRetrieve.getUri();
        String mp3Uri = uri.replace(".json", ".mp3");
        Request request = new Request(
                HttpMethod.GET,
                TwilioRestClient.Domains.API,
                mp3Uri,
                accountSid);
        Response mp3response = Twilio.getRestClient().request(request);
        if (mp3response == null) {
            throw new ApiConnectionException("Recording media fetch failed: Unable to connect to server");
        } else if (!TwilioRestClient.SUCCESS.apply(mp3response.getStatusCode())) {
            RestException restException = RestException.fromJson(mp3response.getStream(), Twilio.getRestClient().getObjectMapper());
            if (restException == null) {
                throw new ApiException("Server Error, no content");
            }
    
            throw new ApiException(
                    restException.getMessage(),
                    restException.getCode(),
                    restException.getMoreInfo(),
                    restException.getStatus(),
                    null);
        }
        return mp3response.getStream();
    }
    

    【讨论】:

    • 使用 7.13.x 。有什么新方法吗? TwilioRestClient.Domains.API,以上行不起作用
    • 在 Android Orio 上的 Twilio SDK 中使用 Recording.reader().read() 时出现错误“没有 Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier 类型的静态字段实例”。我该如何解决这个问题?
    猜你喜欢
    • 2018-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多