2011-08-12 66 views
-1

我真的很沮喪,因爲我不明白爲什麼我的Twilio callStatus REST api不工作:S ...任何想法?twilio休息API調用不工作

它在stackoverflow.php上打電話,但是當它打到yournextnumber.php時,它不執行if語句,因爲callStatus中最有可能沒有值的任何想法爲什麼狀態沒有被髮送?

stackoverflow.php

<?php 
// Include the Twilio PHP library 
require 'Services/Twilio.php'; 

// Twilio REST API version 
$version = "2010-04-01"; 

// Set our Account SID and AuthToken 
$sid = '....'; 
$token = '....'; 


// A phone number you have previously validated with Twilio 
$phonenumber = '....'; 

// Instantiate a new Twilio Rest Client 
$client = new Services_Twilio($sid, $token, $version); 
try { 
    // Initiate a new outbound call 
    $call = $client->account->calls->create(
    $phonenumber, // The number of the phone initiating the call 
    '....', // The number of the phone receiving call 
    'http://demo.twilio.com/welcome/voice/', 
    array('Timeout'=>5, 
      'IfMachine'=>'hangup', 
      'StatusCallback'=>'http://example.com/twilio-twilio-php-28c214f/yourNextNumberHandler.php')); 

    echo 'Started call: ' . $call->sid; 
    echo 'The status of the call is '.$call->status; 
} catch (Exception $e) { 
    echo 'Error: ' . $e->getMessage(); 
} 
?> 

yourNextNumber.php

<?php 
// Include the Twilio PHP library 
    require 'Services/Twilio.php'; 

    // Twilio REST API version 
    $version = "2010-04-01"; 
    print_r()//error_log() $_REQUEST 
    // Set our Account SID and AuthToken 
    $sid = '....'; 
    $token = '....'; 


// A phone number you have previously validated with Twilio 
    $phonenumber = '....'; 

// Instantiate a new Twilio Rest Client 
$client = new Services_Twilio($sid, $token, $version); 


if ($_REQUEST['CallStatus']=='completed') 
{ 

try { 
// Initiate a new outbound call 
$call = $client->account->calls->create(
$phonenumber, // The number of the phone initiating the call 
'..', // The number of the phone receiving call 
'http://demo.twilio.com/welcome/voice/', 
array('Timeout'=>5) 
); 

} 
catch (Exception $e) { 
echo 'Error: ' . $e->getMessage(); 
} 

} 



if ($_REQUEST['CallStatus']=='no-answer') 
{ 

try { 
// Initiate a new outbound call 
$call = $client->account->calls->create(
$phonenumber, // The number of the phone initiating the call 
'...', // The number of the phone receiving call 
'http://demo.twilio.com/welcome/voice/', 
array('Timeout'=>5) 
); 

} 
catch (Exception $e) { 
echo 'Error: ' . $e->getMessage(); 
} 
} 


if ($_REQUEST['CallStatus']=='ringing') 
{ 

try { 
// Initiate a new outbound call 
$call = $client->account->calls->create(
$phonenumber, // The number of the phone initiating the call 
'....', // The number of the phone receiving call 
'http://demo.twilio.com/welcome/voice/', 
array('Timeout'=>5) 
); 

} 
catch (Exception $e) { 
echo 'Error: ' . $e->getMessage(); 
} 
} 


if ($_REQUEST['CallStatus']=='busy') 
{ 

try { 
// Initiate a new outbound call 
$call = $client->account->calls->create(
$phonenumber, // The number of the phone initiating the call 
'...', // The number of the phone receiving call 
'http://demo.twilio.com/welcome/voice/', 
array('Timeout'=>5) 
); 

} 
catch (Exception $e) { 
echo 'Error: ' . $e->getMessage(); 
} 
} 

if ($_REQUEST['CallStatus']=='queued') 
{ 

try { 
// Initiate a new outbound call 
$call = $client->account->calls->create(
$phonenumber, // The number of the phone initiating the call 
'....', // The number of the phone receiving call 
'http://demo.twilio.com/welcome/voice/', 
array('Timeout'=>5) 
); 

} 
catch (Exception $e) { 
echo 'Error: ' . $e->getMessage(); 
} 
} 

    ?> 
+0

'因爲很可能沒有值' - 你至少應該print_r()'/'error_log()''_REQUEST',這樣你就知道它是否有值。 –

回答

2

你檢查你的PHP錯誤日誌?對於這些try塊中的每一個,您都需要catch

+0

問題是日誌文件是隱藏的,我沒有訪問它......所以我可以爲此做任何事情。 – Bulvak

1

而不是使用if語句處理CallStatus,將其轉換爲switch語句。通過這種方式,您可以設置一個無論狀態如何都可以執行的默認情況。然後,當您發現意外的CallStatus時,您可以輕鬆記錄(或通知某人)。