Twilio API 获取通话录音 [英] Twilio API getting the recording of a call

查看:41
本文介绍了Twilio API 获取通话录音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用 PHP 测试 Twilio 的 API.目前我有一个工作模块,它允许我拨打电话并记录它们.现在我正在编写一个模块来报告这些调用.

I am testing Twilio's API in PHP. Currently I have a working module which allows me to place calls and record them. Now I am writing a module to report on those calls.

下面的代码应该获取经过过滤的呼叫列表,并向我的浏览器显示有关该呼叫的一些信息,以及指向录音的链接.此脚本获取通话记录.对于每次调用,它都会调用一个函数来获取属于当前调用的录音.问题是,它每次都获取相同的录音.

The code below is supposed to fetch a filtered list of calls and present my browser with a little info about that call, as well as link to the audio recording. This script fetches call logs. For each call it then calls a function to fetch the recording belonging to the current call. Problem is, it fetches the same audio recording every time.

    $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)." &nbsp; ".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 "&nbsp; &nbsp; ->".$callsid." <strong><a href='http://api.twilio.com".$recording->uri."'>Audio</a></strong>";
        }
    }

输出是这样的(请注意每个音频文件都有相同的 URL):

The output is this (please notice that every audio file has the same URL):

CAab40cacf1690a86e604ba0f527153887, 1, $0.015 &nbsp; &nbsp; &nbsp; ->CAab40cacf1690a86e604ba0f527153887 <strong><a href='http://api.twilio.com/2010-04-01/Accounts/acctnumber/Recordings/REe9a199dec7376ef94d6af256749e7d81'>Audio</a></strong>
CAaf5629839a6d2095067a04359dc13809, 14, $0.015 &nbsp; &nbsp; &nbsp; ->CAaf5629839a6d2095067a04359dc13809 <strong><a href='http://api.twilio.com/2010-04-01/Accounts/acctnumber/Recordings/REe9a199dec7376ef94d6af256749e7d81'>Audio</a></strong>
CAa8610e49f6e49a71c8bf3e02d3e974f1, 11, $0.015 &nbsp; &nbsp; &nbsp; ->CAa8610e49f6e49a71c8bf3e02d3e974f1 <strong><a href='http://api.twilio.com/2010-04-01/Accounts/acctnumber/Recordings/REe9a199dec7376ef94d6af256749e7d81'>Audio</a></strong>
CA478704a99883f919a9932b52c6971cf7, 21, $0.015 &nbsp; &nbsp; &nbsp; ->CA478704a99883f919a9932b52c6971cf7 <strong><a href='http://api.twilio.com/2010-04-01/Accounts/acctnumber/Recordings/REe9a199dec7376ef94d6af256749e7d81'>Audio</a></strong>
CA00b2f9db896e3b8cfc82c93df5c8e11e, 9, $0.015 &nbsp; &nbsp; &nbsp; ->CA00b2f9db896e3b8cfc82c93df5c8e11e <strong><a href='http://api.twilio.com/2010-04-01/Accounts/acctnumber/Recordings/REe9a199dec7376ef94d6af256749e7d81'>Audio</a></strong>
CAcbd21d8dd3de1c06ce1f393c987bc6c7, 19, $0.015 &nbsp; &nbsp; &nbsp; ->CAcbd21d8dd3de1c06ce1f393c987bc6c7 <strong><a href='http://api.twilio.com/2010-04-01/Accounts/acctnumber/Recordings/REe9a199dec7376ef94d6af256749e7d81'>Audio</a></strong>
CAffb1d60f5f48b870af65329d7d4ca48f, 4, $0.015 &nbsp; &nbsp; &nbsp; ->CAffb1d60f5f48b870af65329d7d4ca48f <strong><a href='http://api.twilio.com/2010-04-01/Accounts/acctnumber/Recordings/REe9a199dec7376ef94d6af256749e7d81'>Audio</a></strong>
CA44fd1b5b9ef347f730d068abafffbd73, 15, $0.015 &nbsp; &nbsp; &nbsp; ->CA44fd1b5b9ef347f730d068abafffbd73 <strong><a href='http://api.twilio.com/2010-04-01/Accounts/acctnumber/Recordings/REe9a199dec7376ef94d6af256749e7d81'>Audio</a></strong>

推荐答案

Twilio 开发人员布道者在这里.

Twilio developer evangelist here.

查询的参数区分大小写,因此您需要将 callSid 中的 c 大写.用单引号包裹字符串也不能替代它.

The parameters for queries are case sensitive so you need to capitalize the c in callSid. Also wrapping a string in single quotes doesn't substitute it.

foreach ($client->account->recordings->getIterator(0, 50, array(
                "callSid" => '$callsid'

foreach ($client->account->recordings->getIterator(0, 50, array(
                "CallSid" => $callsid

如果我能提供更多帮助,请告诉我!

Please let me know if I can help further!

为了澄清正在发生的事情,由于查询参数关闭,并且每次获取集合中的第一个并返回该记录,因此请求获取帐户中的所有记录.从而使它们都相同.

edit: To clarify what was happening, a request was being made to get all the recordings in the account since the query param was off and each time it was taking the first one of the collection and returning that. Thus causing them to all be the same.

这篇关于Twilio API 获取通话录音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆