2016-12-06 58 views
1

当我使用twilio我获得以下错误发送消息:致命错误,而试图用twilio阿比phpSDK

PHP Catchable fatal error: Argument 2 passed to Twilio\Rest\Api\V2010\Account\MessageInstance::__construct() must be of the type array, null given, called in /data/home/changliang/twilio/twilio-php-master/Twilio/Rest/Api/V2010/Account/MessageList.php on line 69 and defined in /data/home/changliang/twilio/twilio-php-master/Twilio/Rest/Api/V2010/Account/MessageInstance.php on line 52

这是我的代码。

require_once("/twilio/twilio-php-master/Twilio/autoload.php"); 
use Twilio\Rest\Client; 
$to = '+12022022022' 
$content = 'hello'; 
$sid = 'XXXXXXX'; 
$token = 'XXXXXXXX'; 
$client = new Client($sid, $token); 
$sms = $client->account->messages->create( 
    $to, 
    array(
     'from' => '+12346788xx', 
     'body' => $content, 
    ) 
); 

回答

3

有同样的错误。您的请求是否可以通过公司代理服务器完成?这是这个问题。代理服务器在这里增加了一个额外的HTTP标头的响应头也正因为如此的CurlClient不能正确解析响应体:

HTTP/1.1 200 Connection established

我把它固定通过添加额外的头围绕线CurlClient类跳过37:

原文:

list($head, $body) = ($parts[0] == 'HTTP/1.1 100 Continue') 
          ? array($parts[1], $parts[2]) 
          : array($parts[0], $parts[1]); 

新:

list($head, $body) = ($parts[0] == 'HTTP/1.1 100 Continue' 
        || $parts[0] == 'HTTP/1.1 200 Connection established') 
          ? array($parts[1], $parts[2]) 
          : array($parts[0], $parts[1]); 
+0

工作没有任何问题。卷曲客户端被放置在目录中:twilio_outbound_phone_call/twilio-php-master/Twilio/Http –