2016-11-16 18 views
0

twilioのウェブサイトには、すべてのガイドがこの問題で古くなっているようです。各コールレコードのtwilio録音を取得

すべてのコールのリストを取得しようとしていて、録音レコードの各コールレコードチェックで、録音レコードがある場合はそれを取得します。私は非常に非常に遅く、そして予想通りdoesntの仕事で、このスクリプトを実行しようと何イムを行うための正しい方法であると思ういけないが

は、今ここでどこイムです:

// Set our AccountSid and AuthToken 
$sid = 'MY_SID'; 
$token = 'MY_TOKEN'; 

// Your Account Sid and Auth Token from twilio.com/user/account 
$client = new Client($sid, $token); 

// Loop over the list of calls and echo a property for each one 
foreach ($client->account->calls->read() as $call 
) { 
    echo $call->sid.", &nbsp; ".getRecording($call->sid)."<br/>"; 


} 

function getRecording($callsid){ 


    // Set our AccountSid and AuthToken 
    $sid = 'MY_SID'; 
    $token = 'MY_TOKEN'; 
    $client = new Client($sid, $token); 

    // Loop over the list of recordings and echo a property for each one 
    foreach ($client->account->recordings->read(array("CallSid" => $callsid)) as $recording) { 

     return "&nbsp; &nbsp; ->".$callsid." <a href='http://api.twilio.com".$recording->uri."'>Audio</a> "; 

    } 
} 

出力すべての録音URIがそれぞれ同じであるということです。

CAb5323eed7ed4f82b3990830777c02684,  ->CAb5323eed7ed4f82b3990830777c02684 <a href='http://api.twilio.com/2010-04-01/Accounts/My_account_nr/Recordings/RE9f96dc253140ffdfa8cd37c139de978s.json'>Audio</a> 
CA57df3525265949c4dfcaa9073b02880a,  ->CA57df3525265949c4dfcaa9073b02880a <a href='http://api.twilio.com/2010-04-01/Accounts/My_account_nr/Recordings/RE9f96dc253140ffdfa8cd37c139de978s.json'>Audio</a> 
CA31f0ac07483d72a56d424b55672a61ab,  ->CA31f0ac07483d72a56d424b55672a61ab <a href='http://api.twilio.com/2010-04-01/Accounts/My_account_nr/Recordings/RE9f96dc253140ffdfa8cd37c139de978s.json'>Audio</a> 
CAac6e6f0d45cd15069300202ce6cbc27e,  ->CAac6e6f0d45cd15069300202ce6cbc27e <a href='http://api.twilio.com/2010-04-01/Accounts/My_account_nr/Recordings/RE9f96dc253140ffdfa8cd37c139de978s.json'>Audio</a> 
CAe51db5d605b94c7141d43611bc8dbbd1,  ->CAe51db5d605b94c7141d43611bc8dbbd1 <a href='http://api.twilio.com/2010-04-01/Accounts/My_account_nr/Recordings/RE9f96dc253140ffdfa8cd37c139de978s.json'>Audio</a> 
CAbe46fe9ab0202fc15184915b0af94d1a,  ->CAbe46fe9ab0202fc15184915b0af94d1a <a href='http://api.twilio.com/2010-04-01/Accounts/My_account_nr/Recordings/RE9f96dc253140ffdfa8cd37c139de978s.json'>Audio</a> 
CA15c3eaccc8b1cfca648105744c1c1c8c,  ->CA15c3eaccc8b1cfca648105744c1c1c8c <a href='http://api.twilio.com/2010-04-01/Accounts/My_account_nr/Recordings/RE9f96dc253140ffdfa8cd37c139de978s.json'>Audio</a> 
CAcb9a5d1f7e3f3b4f3b1eff08f4e51094,  ->CAcb9a5d1f7e3f3b4f3b1eff08f4e51094 <a href='http://api.twilio.com/2010-04-01/Accounts/My_account_nr/Recordings/RE9f96dc253140ffdfa8cd37c139de978s.json'>Audio</a> 
CAfc6a986c4e58e35778d4242303f37e32,  ->CAfc6a986c4e58e35778d4242303f37e32 <a href='http://api.twilio.com/2010-04-01/Accounts/My_account_nr/Recordings/RE9f96dc253140ffdfa8cd37c139de978s.json'>Audio</a> 
CA58aa5dc00c72567b91b43db52577080a,  ->CA58aa5dc00c72567b91b43db52577080a <a href='http://api.twilio.com/2010-04-01/Accounts/My_account_nr/Recordings/RE9f96dc253140ffdfa8cd37c139de978s.json'>Audio</a> 
CA65dbdee33266a706f17616ecf03e78eb,  ->CA65dbdee33266a706f17616ecf03e78eb <a href='http://api.twilio.com/2010-04-01/Accounts/My_account_nr/Recordings/RE9f96dc253140ffdfa8cd37c139de978s.json'>Audio</a> 

これはうまくいかないし、これも非常にゆっくりと実行されているので、より良い解決策を探しています。

答えて

0

あなたは、 `RExxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx」のようなものを正しい記録IDを持っていたら:

MP3形式のURLが

https://api.twilio.com/2010-04-01/Accounts/ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/Recordings/RExxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.mp3?Download=false

でまた

fromat WAVのURLを取得することができます

https://api.twilio.com/2010-04-01/Accounts/ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/Recordings/RExxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.wav?Download=false

+0

こんにちは、ありがとうございました......これは私が探していたものではありません....問題は、私のコードはforeach内foreachがあり、非常に遅い読み込みページになりました。私は記事で言ったように、これはうまくいかないし、非常にゆっくりと動いているので、より良い解決策を探しています。しかし、あなたの時間に感謝します:-) – user2014557

1

Twilioデベロッパーエバンジェリストはこちら

あなたはすべての呼び出しをループしているので、REST API経由で呼び出しのすべての記録をループするのは非常に遅くなります。録音を表示するには、この方法をとらないことをお勧めします。

代わりに、できることは2つあります。

まず、既存のものと似たスクリプトを作成します。ただし、HTMLを書き出す代わりに、呼び出しとその録音をデータベースに保存します。そうすれば、独自のデータベースを見ることができます。これは、APIへの複数の呼び出しよりもはるかに迅速です。

第2に、新しいスクリプトを更新するためにスクリプトを実行し続けるのではなく、呼び出し時にrecordingStatusCallbacksを使用できます。これにより、新しい呼び出しの録音が完了したときにアプリケーションにall the information on the recordingsというHTTP要求が送信されるようにWebhook URLを設定できます。それをデータベースに保存することもできます。アプリケーションはすべての最新の録画で更新されます。

それが役立つかどうか教えてください。

1

これは実際には非常に迅速かつ素晴らしい方法です。 Twilio社の従業員が提供するソリューション。ありがとう

$client = new Client($sid, $token); 

// Create an array of recordings 
$recording_array = array(); 
// Loop over the list of recordings and echo a property for each one 
foreach ($client->recordings->read() as $recording) { 
    $recording_array[$recording->callSid][$count] = $recording->sid; 
    $count++; 
} 


foreach ($client->account->calls->read() as $call) { 
    // Check if there is a call sid exist 
    if(array_key_exists($call->sid, $recording_array)){ 
     foreach($recording_array["$call->sid"] as $key=>$val){ 
      echo $call->sid.", Recording is ".$val."\r\n"; 
     } 
    } else { 
     echo $call->sid."\r\n"; 
    } 
} 
関連する問題