简体   繁体   English

Twilio Video API 以字符串形式返回 MKV 文件以响应录制

[英]Twilio Video API Returns MKV File as a String in Response of Recording

I have a problem retrieving the Recordings in Twilio Video API.我在检索 Twilio Video API 中的录音时遇到问题。

I'm using C# in the back-end and have successfully gotten the Recording sids of the rooms.我在后端使用 C# 并成功获得了房间的录音 sid。

 const string apiKeySid = "SKXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
                const string apiKeySecret = "byt32MXXXXXXXXXXXXXXXXXXXXX";

                TwilioClient.Init(apiKeySid, apiKeySecret);

                string recordingSid = sample.RecordingSid;
                var uri = $"https://video.twilio.com/v1/Recordings/{recordingSid}/Media";
                var response = TwilioClient.GetRestClient().Request(new Request(HttpMethod.Get, uri));

                var mediaLocation =JsonConvert.DeserializeObject<Dictionary<string, string>>(response.Content)["location"];
                using (var webClient = new System.Net.WebClient())
                {
                    string mediaContent = webClient.DownloadString(uri);
                }

This is my code to download the recording from the Twilio Servers.这是我从 Twilio 服务器下载录音的代码。

The Response回应

Content: "\u001aEߣ\u0001\0\0\0\0\0\0\u0014B��matroska\0B��\u0002B��...." A very long text which I think is an mkv file
StatusCode: OK

The ERROR错误

var mediaLocation =JsonConvert.DeserializeObject<Dictionary<string, string>>(response.Content)["location"];

As the content contains gibberish, the code doesn't work from this line onwards.由于内容包含胡言乱语,代码从这一行开始不起作用。

What I've tried 1) Tried to copy the content, paste it in Notepad and then save the file, in Unicode as well as in ASCII code, change the format of file to ".mkv" and try to run it.我尝试过的1) 尝试复制内容,将其粘贴到记事本中,然后以 Unicode 和 ASCII 代码保存文件,将文件格式更改为“.mkv”并尝试运行它。 PS Doesn't Work. PS 不起作用。 2) Tried to Download the File (both from my C# code and manually in browser) from "https://video.twilio.com/v1/Recordings/{recordingSid}/Media" , gives Authentication Required Error 3) Tried my best to convert the string to mkv but to no avail. 2) 尝试从"https://video.twilio.com/v1/Recordings/{recordingSid}/Media"下载文件(从我的 C# 代码和在浏览器中手动下载),给出需要身份验证的错误 3)尽我所能将字符串转换为 mkv 但无济于事。

What the Official Documentation Says官方文档怎么说

{
"location": "https://com.twilio.dev-us1.video.recording.s3.amazonaws.com/RTXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"

} Which is not what the API returns, maybe they have changed it recently but they should update it in their documentation.这不是 API 返回的内容,也许他们最近更改了它,但他们应该在他们的文档中更新它。

What I need help in If you have used Twilio's Video API before, can you tell me how can I retrieve the recording from the Twilio Server assuming I have the Room SID and Recording Sid of the recording.我需要什么帮助如果您之前使用过 Twilio 的视频 API,您能告诉我如何从 Twilio 服务器检索录音,假设我有录音的房间 SID 和录音 Sid。

Thanks in Advance :)提前致谢:)

I solved it myself When I write this url in the browser https://video.twilio.com/v1/Recordings/{recordingSid}/Media And write the Account_Sid as the username and Account_Secret as the password, it lets me download the file directly.我自己解决了当我在浏览器中写这个 url https://video.twilio.com/v1/Recordings/{recordingSid}/Media并写 Account_Sid 作为用户名和 Account_Secret 作为密码时,它让我下载文件直接。 So what I've done is that everytime I want to access a recording, I send a GET request to this url https://video.twilio.com/v1/Recordings/{recordingSid}/Media Along with the account sid and account secret and it lets me download the recording direcly.所以我所做的是每次我想访问录音时,我都会向这个 url https://video.twilio.com/v1/Recordings/{recordingSid}/Media以及帐户 sid 和帐户发送一个 GET 请求秘密,它让我可以直接下载录音。

I'm posting this answer for anyone who has come across this same issue in the future.我正在为将来遇到相同问题的任何人发布此答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM