我正在开发一个通过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
类,并使用它使调用更加容易:
// 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
对象应该会有所帮助。
请查看有关创建呼叫的文档,或者如果您需要任何进一步的帮助,请告诉我。