2011-08-12 11 views
-1

なぜ私のTwilio callStatusがREST API用に動作していないのかわからないので、私は本当に不満です。twilio残りのAPI呼び出しが動作しない

これはstackoverflow.phpで呼び出されますが、yournextnumber.phpにヒットしたときには、callStatusに値がない可能性が高いため、ifステートメントが実行されません。

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のエラーログを確認しましたか?それらのブロックのそれぞれに対してcatchが必要です。

+0

問題は、ログファイルが隠されていてアクセスできないということです。そのために何かできます。 – Bulvak

1

CallStatus処理にifステートメントを使用する代わりに、switchステートメントに変換します。これにより、ステータスに関係なく実行されるデフォルトのケースを設定できます。その後、予期せぬCallStatusを見つけたら、簡単にログに記録(または誰かに通知)することができます。

関連する問題