如何在twilio中使用StatusCallback url

时间:2012-03-20 12:11:49

标签: twilio

<?php
$options = array(
  "StatusCallback" => 'http://173.203.104.63/call/out/log-callback.php?  id='.$id
);

$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
    $cphonenumber, // The number of the phone receiving call
    '60',
    'http://173.203.104.63/call/out/three.php?id='.$id, // The URL Twilio will request when the call is answered
    $options
  );
...

这里我已经为statuscallback设置了网址,但我不知道天气是否重定向,以及如何在该网址中获取我的callstatus值

3 个答案:

答案 0 :(得分:1)

第三个参数应该是URL,而不是'60'。通话结束后,所有数据都会以正常的POSTGET参数传递到您的回调网址(具体取决于您在帐户中设置的内容)。

答案 1 :(得分:0)

您忘记为statuscallback网址指定方法

我已将其包含在代码

    <?php
//"StatusCallbackMethod" can be "POST" or "GET", depends on the way you recieve it on your StatusCallback,
    $options = array(
      "StatusCallbackMethod"=>"GET",
      "StatusCallback" => 'http://173.203.104.63/call/out/log-callback.php?  id='.$id
    );

$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
    $cphonenumber, // The number of the phone receiving call
    '60',
    'http://173.203.104.63/call/out/three.php?id='.$id, // The URL Twilio will request when the call is answered
    $options
  );

答案 2 :(得分:0)

<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); //  

// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "AC5ef8732a3c49700934481addd5ce1659";
$token = "{{ auth_token }}";
$client = new Services_Twilio($sid, $token);
$call = $client->account->calls->create("+18668675309", "+14155551212",      "http://demo.twilio.com/docs/voice.xml", array(
    "Method" => "GET",
   "StatusCallback" => "https://www.myapp.com/events",
   "StatusCallbackMethod" => "POST",
   "StatusCallbackEvent" => array("initiated", "ringing", "answered", "completed"),
));
echo $call->sid;

请参阅https://www.twilio.com/docs/api/rest/making-calls