在 Twilio 中进行会议时出错

Error while doing conferencing in Twilio

我正在开发一个通过 Twilio API 进行语音通话的应用程序 但是它在第一次调用后就断开了。

这是我的代码:

my index.php

<?php
$serverroot=$_SERVER['DOCUMENT_ROOT'].'/twilioapi/twilio-php-master/Services/Twilio.php';
require($serverroot); 
$version = "2010-04-01"; 
 $num= '+1 218-461-4418';
 $num1= '+91$$$$$$$$$$$';
 $num2= '+91$$$$$$$$$$$';
 $num3= '+91$$$$$$$$$$$';  

$account_sid = '$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$'; 
$auth_token = '$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$'; 
$client = new TwilioRestClient($account_sid, $auth_token); 

  $participants = array($num1, $num2, $num3);

  // Go through the participants array and call each person.
  foreach ($participants as $particpant)
  {
    $vars = array(
      'From' => $num,
      'To' => $participant,
      'Url' => 'http://my_url.com/twilioapi/mytest2.xml');

    echo $response = $client->request("/$version/Accounts/$account_sid/Calls", "GET", $vars);
  }

//echo json_encode($response);

?>

xml file

<Response>
    <Say>Joining a conference room</Say>
       <Dial>
         <Conference>MyRoom</Conference>
       </Dial>
</Response>

问候

这里是 Twilio 开发人员布道者。

我不确定为什么您的代码会拨打一个电话然后断开连接。我可以告诉你一件事我会做不同的事情,这可能会有所帮助。

而不是像您那样使用 TwilioRestClient 对象调用 API:

// Set up $client
$client = new TwilioRestClient($account_sid, $auth_token); 
// Make request (using $vars from loop)
$client->request("/$version/Accounts/$account_sid/Calls", "GET", $vars);

您实际上可以要求 Services_Twilio class 并使用它更轻松地调用:

// set up $client
$client = new Sevices_Twilio($account_sid, $auth_token);

// set up participants then...

foreach ($participants as $particpant) {
  echo $response = $client->account->calls->create(
    $num,          // The from number
    $participant,  // The to number
    'http://my_url.com/twilioapi/mytest2.xml'
  );

}

我想到的另一件事。调用 Calls 端点以创建调用应该是 POST 而不是 GET。也许这就是它失败的原因。不过,使用 Services_Twilio 对象应该会有所帮助。

看看 documentation on creating calls 或者如果您需要任何进一步的帮助,请告诉我。