因此,我正在创建一个允许用户通过Twilio录制消息的应用程序,并尝试在录制完成后立即在MySQLi数据库中存储RecordingSID、创建日期和录制的持续时间。我已经设法通过使用substr()函数从RecordingURL中取出最后34位数字来获取RecordingSID,并且只需获取数据库表中日期创建字段的今天日期。然而,似乎无论实际录制的时间有多长,当我尝试获取录制持续时间时,我都会不断地得到值8。这是我现在得到的(省略了数据库插入,因为它们可以工作):
<?php
$recordingURL = $_REQUEST['RecordingUrl'];
$recordingSID = substr($recordingURL, -34);
date_default_timezone_set('EST');
$dateCreated = date("Y-m-d");
$duration = $_REQUEST['RecordingDuration'];
?>在这个问题上的任何帮助都将是非常棒的!谢谢!
编辑:我还尝试了以下解决方案,取代了前面代码片段中的最后一行:
<?php
$recordings = $client->account->recordings->getIterator(0, 50, array('Sid' => $recordingSID,));
foreach ($recordings as $recording)
{
$duration = $recording->duration;
}
?>发布于 2014-12-08 11:55:57
根据您粘贴的代码示例,您可能做了几件不正确的事情。如果我错了,请纠正我的错误,但我相信,在您提交了一个带有Twilio js及其TwiML的Recording资源之后,您正试图从Twilio API请求回一个API资源
如果是这样的话,twilio实际上有一个很好的小demo,完全符合您的用例。
你在$_REQUEST['RecordingDuration']中应该看不到任何东西,我不确定为什么你会得到一个8的返回值。基本上,您要做的是使用Twilio REST API查找用户的录音。
下面是一个示例代码片段:
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library
// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACda6f132a3c49700934481addd5ce1659";
$token = "{{ auth_token }}";
$client = new Services_Twilio($sid, $token);
// Loop over the list of recordings and echo a property for each one
foreach ($client->account->recordings as $recording) {
echo $recording->duration;
}API调用的响应将返回录制资源。
下面是来自他们的docs的更多示例
https://stackoverflow.com/questions/27350951
复制相似问题