Twilio API 正在获取通话录音
Twilio API getting the recording of a call
我正在 PHP 中测试 Twilio 的 API。目前我有一个工作模块,可以让我拨打电话并进行录音。现在我正在编写一个模块来报告这些调用。
下面的代码应该获取过滤后的呼叫列表,并向我的浏览器显示有关该呼叫的一些信息,以及 link 录音。此脚本获取通话记录。对于每次调用,它都会调用一个函数来获取属于当前调用的记录。问题是,它每次都获取相同的录音。
$version = '2010-04-01';
// Set our AccountSid and AuthToken
$sid = 'abc123';
$token = 'fbc123';
// Your Account Sid and Auth Token from twilio.com/user/account
$client = new Services_Twilio($sid, $token,$version);
$dt = date("Y-m-d");
// Loop over the list of calls and echo a property for each one
foreach ($client->account->calls->getIterator(0, 50, array(
"Status" => "completed",
"StartTime>" => "2015-08-04",
"StartTime<" => "$dt"
)) as $call
) {
echo $call->sid.", ".$call->duration.", $".abs($call->price)." ".getRecording($call->sid)."<br/>";
}
function getRecording($callsid){
// Twilio REST API version
$version = '2010-04-01';
// Set our AccountSid and AuthToken
$sid = 'abc123';
$token = 'fbc123';
$client = new Services_Twilio($sid, $token);
// Loop over the list of recordings and echo a property for each one
foreach ($client->account->recordings->getIterator(0, 50, array(
"callSid" => '$callsid'
)) as $recording
) {
return " ->".$callsid." <strong><a href='http://api.twilio.com".$recording->uri."'>Audio</a></strong>";
}
}
输出是这样的(请注意每个音频文件都有相同的URL):
CAab40cacf1690a86e604ba0f527153887, 1, [=12=].015 ->CAab40cacf1690a86e604ba0f527153887 <strong><a href='http://api.twilio.com/2010-04-01/Accounts/acctnumber/Recordings/REe9a199dec7376ef94d6af256749e7d81'>Audio</a></strong>
CAaf5629839a6d2095067a04359dc13809, 14, [=12=].015 ->CAaf5629839a6d2095067a04359dc13809 <strong><a href='http://api.twilio.com/2010-04-01/Accounts/acctnumber/Recordings/REe9a199dec7376ef94d6af256749e7d81'>Audio</a></strong>
CAa8610e49f6e49a71c8bf3e02d3e974f1, 11, [=12=].015 ->CAa8610e49f6e49a71c8bf3e02d3e974f1 <strong><a href='http://api.twilio.com/2010-04-01/Accounts/acctnumber/Recordings/REe9a199dec7376ef94d6af256749e7d81'>Audio</a></strong>
CA478704a99883f919a9932b52c6971cf7, 21, [=12=].015 ->CA478704a99883f919a9932b52c6971cf7 <strong><a href='http://api.twilio.com/2010-04-01/Accounts/acctnumber/Recordings/REe9a199dec7376ef94d6af256749e7d81'>Audio</a></strong>
CA00b2f9db896e3b8cfc82c93df5c8e11e, 9, [=12=].015 ->CA00b2f9db896e3b8cfc82c93df5c8e11e <strong><a href='http://api.twilio.com/2010-04-01/Accounts/acctnumber/Recordings/REe9a199dec7376ef94d6af256749e7d81'>Audio</a></strong>
CAcbd21d8dd3de1c06ce1f393c987bc6c7, 19, [=12=].015 ->CAcbd21d8dd3de1c06ce1f393c987bc6c7 <strong><a href='http://api.twilio.com/2010-04-01/Accounts/acctnumber/Recordings/REe9a199dec7376ef94d6af256749e7d81'>Audio</a></strong>
CAffb1d60f5f48b870af65329d7d4ca48f, 4, [=12=].015 ->CAffb1d60f5f48b870af65329d7d4ca48f <strong><a href='http://api.twilio.com/2010-04-01/Accounts/acctnumber/Recordings/REe9a199dec7376ef94d6af256749e7d81'>Audio</a></strong>
CA44fd1b5b9ef347f730d068abafffbd73, 15, [=12=].015 ->CA44fd1b5b9ef347f730d068abafffbd73 <strong><a href='http://api.twilio.com/2010-04-01/Accounts/acctnumber/Recordings/REe9a199dec7376ef94d6af256749e7d81'>Audio</a></strong>
这里是 Twilio 开发人员布道者。
查询的 parameters 区分大小写,因此您需要将 callSid
中的 c
大写。同样,用单引号括起一个字符串并不能替代它。
foreach ($client->account->recordings->getIterator(0, 50, array(
"callSid" => '$callsid'
至
foreach ($client->account->recordings->getIterator(0, 50, array(
"CallSid" => $callsid
如果我能提供进一步的帮助,请告诉我!
编辑:为了澄清发生了什么,请求获取帐户中的所有记录,因为查询参数已关闭,并且每次它都获取集合中的第一个并返回它。从而导致它们都是一样的。
我正在 PHP 中测试 Twilio 的 API。目前我有一个工作模块,可以让我拨打电话并进行录音。现在我正在编写一个模块来报告这些调用。
下面的代码应该获取过滤后的呼叫列表,并向我的浏览器显示有关该呼叫的一些信息,以及 link 录音。此脚本获取通话记录。对于每次调用,它都会调用一个函数来获取属于当前调用的记录。问题是,它每次都获取相同的录音。
$version = '2010-04-01';
// Set our AccountSid and AuthToken
$sid = 'abc123';
$token = 'fbc123';
// Your Account Sid and Auth Token from twilio.com/user/account
$client = new Services_Twilio($sid, $token,$version);
$dt = date("Y-m-d");
// Loop over the list of calls and echo a property for each one
foreach ($client->account->calls->getIterator(0, 50, array(
"Status" => "completed",
"StartTime>" => "2015-08-04",
"StartTime<" => "$dt"
)) as $call
) {
echo $call->sid.", ".$call->duration.", $".abs($call->price)." ".getRecording($call->sid)."<br/>";
}
function getRecording($callsid){
// Twilio REST API version
$version = '2010-04-01';
// Set our AccountSid and AuthToken
$sid = 'abc123';
$token = 'fbc123';
$client = new Services_Twilio($sid, $token);
// Loop over the list of recordings and echo a property for each one
foreach ($client->account->recordings->getIterator(0, 50, array(
"callSid" => '$callsid'
)) as $recording
) {
return " ->".$callsid." <strong><a href='http://api.twilio.com".$recording->uri."'>Audio</a></strong>";
}
}
输出是这样的(请注意每个音频文件都有相同的URL):
CAab40cacf1690a86e604ba0f527153887, 1, [=12=].015 ->CAab40cacf1690a86e604ba0f527153887 <strong><a href='http://api.twilio.com/2010-04-01/Accounts/acctnumber/Recordings/REe9a199dec7376ef94d6af256749e7d81'>Audio</a></strong>
CAaf5629839a6d2095067a04359dc13809, 14, [=12=].015 ->CAaf5629839a6d2095067a04359dc13809 <strong><a href='http://api.twilio.com/2010-04-01/Accounts/acctnumber/Recordings/REe9a199dec7376ef94d6af256749e7d81'>Audio</a></strong>
CAa8610e49f6e49a71c8bf3e02d3e974f1, 11, [=12=].015 ->CAa8610e49f6e49a71c8bf3e02d3e974f1 <strong><a href='http://api.twilio.com/2010-04-01/Accounts/acctnumber/Recordings/REe9a199dec7376ef94d6af256749e7d81'>Audio</a></strong>
CA478704a99883f919a9932b52c6971cf7, 21, [=12=].015 ->CA478704a99883f919a9932b52c6971cf7 <strong><a href='http://api.twilio.com/2010-04-01/Accounts/acctnumber/Recordings/REe9a199dec7376ef94d6af256749e7d81'>Audio</a></strong>
CA00b2f9db896e3b8cfc82c93df5c8e11e, 9, [=12=].015 ->CA00b2f9db896e3b8cfc82c93df5c8e11e <strong><a href='http://api.twilio.com/2010-04-01/Accounts/acctnumber/Recordings/REe9a199dec7376ef94d6af256749e7d81'>Audio</a></strong>
CAcbd21d8dd3de1c06ce1f393c987bc6c7, 19, [=12=].015 ->CAcbd21d8dd3de1c06ce1f393c987bc6c7 <strong><a href='http://api.twilio.com/2010-04-01/Accounts/acctnumber/Recordings/REe9a199dec7376ef94d6af256749e7d81'>Audio</a></strong>
CAffb1d60f5f48b870af65329d7d4ca48f, 4, [=12=].015 ->CAffb1d60f5f48b870af65329d7d4ca48f <strong><a href='http://api.twilio.com/2010-04-01/Accounts/acctnumber/Recordings/REe9a199dec7376ef94d6af256749e7d81'>Audio</a></strong>
CA44fd1b5b9ef347f730d068abafffbd73, 15, [=12=].015 ->CA44fd1b5b9ef347f730d068abafffbd73 <strong><a href='http://api.twilio.com/2010-04-01/Accounts/acctnumber/Recordings/REe9a199dec7376ef94d6af256749e7d81'>Audio</a></strong>
这里是 Twilio 开发人员布道者。
查询的 parameters 区分大小写,因此您需要将 callSid
中的 c
大写。同样,用单引号括起一个字符串并不能替代它。
foreach ($client->account->recordings->getIterator(0, 50, array(
"callSid" => '$callsid'
至
foreach ($client->account->recordings->getIterator(0, 50, array(
"CallSid" => $callsid
如果我能提供进一步的帮助,请告诉我!
编辑:为了澄清发生了什么,请求获取帐户中的所有记录,因为查询参数已关闭,并且每次它都获取集合中的第一个并返回它。从而导致它们都是一样的。