2013-10-25 54 views
1

我正在開發一個twilio應用程序,其中的聲音被轉錄並轉換爲文本。在檢索轉錄文本之前,所有功能都是有效的。我知道如果我知道「sid」,我可以檢索轉錄代碼,但如果我想動態轉錄代碼並且不知道「sid」,該怎麼辦?換句話說,我想從電話號碼「555-555-1212」的最新轉錄,我可以找到下面的代碼。在不知道sid的情況下在php中檢索twilio轉錄文本

<?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 = "AC1240edf87a1d3b6717472af6deda4ce7"; 
$token = "{{ auth_token }}"; 
$client = new Services_Twilio($sid, $token); 
$client->account->transcriptions->delete("TR8c61027b709ffb038236612dc5af8723"); 
?> 

在此先感謝! Diego

回答

0

修正了我原來的問題=)

<?php 
//RETRIEVE NUMBERS LAST TRANSCRIPTION 
$client = new Services_Twilio($sid, $token); 
$i=0; 
foreach($client->account->transcriptions->getIterator(0, 50, array('Status' => 'completed', 'To' => ''.$_GET['number'].'')) as $call) { 
//now use the sid to get the transcription text using a seperate rest call. 
if($i==1) break; 
$transcription = $client->account->transcriptions->get($call->sid); 
$sms_text = $transcription->transcription_text; 
$i++; 
} 
?> 
0

您將需要獲取呼叫的SID,但如果您知道電話號碼並可選擇查找日期範圍(我的PHP已生鏽,因此您可能需要這裏

// Your Account Sid and Auth Token from twilio.com/user/account 
$sid = "{{ sid }}"; 
$token = "{{ auth_token }}"; 
$client = new Services_Twilio($sid, $token); 

// Get calls to a number on or after a certain date. 
foreach ($client->account->calls->getIterator(0, 50, array("Status" => "completed", "To" => "555-555-1212","StartTime" => "2013-10-26")) as $call) { 
    echo $call->sid 
    //now use the sid to get the transcription text using a seperate rest call. 
    $transcription = $client->account->transcriptions->get($call->sid); 
    echo $transcription->transcription_text;  
} 
+0

echo $ transcription-> transcription_text;拋出以下錯誤 - >致命錯誤:未找到異常'Services_Twilio_RestException'與消息'所請求的資源未找到' 看來調用sid和transcrption sid是完全不同的... – Dango

相關問題