twilio休息api呼叫使不工作

时间:2011-08-12 18:01:29

标签: php twilio

我真的很沮丧,因为我无法弄清楚为什么我的Twilio callStatus用于REST api不起作用:S ......有什么想法吗?

它在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();
}
}

    ?>

2 个答案:

答案 0 :(得分:2)

您检查过PHP错误日志吗? catch块需要try

答案 1 :(得分:1)

不使用if语句进行CallStatus处理,而是将其转换为switch语句。这样,您可以设置无论状态如何都会执行的默认情况。然后,当您发现意外的CallStatus时,您可以轻松地记录(或通知某人)。