我的代码有点问题!我试图在twilio中为子帐户创建一个地址(为了购买一些需要地址的号码)。
我的代码:
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
// Get the PHP helper library from twilio.com/docs/php/install
require __DIR__ . '/twilio-php-master/Twilio/autoload.php';
use Twilio\Rest\Client;
// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "xxxxx";
$token = "xxxx";
$client = new Client($sid, $token);
$address = $client->addresses->create(
array(
"CustomerName" => "Customer",
"Street" => "2 rue du chapelier ",
"City" => "",
"Region" => "France",
"PostalCode" => "75020",
"IsoCountry" => "FR",
)
);
?>
我收到了这个错误
警告:缺少Twilio \ Rest \ Api \ V2010 \ Account \ AddressList :: create()的参数2,在第26行的/Applications/MAMP/htdocs/taddresses.php中调用,并在/ Applications / MAMP / htdocs中定义第49行/twilio-php-master/Twilio/Rest/Api/V2010/Account/AddressList.php
警告:缺少Twilio \ Rest \ Api \ V2010 \ Account \ AddressList :: create()的参数3,在第26行的/Applications/MAMP/htdocs/taddresses.php中调用,并在/ Applications / MAMP / htdocs中定义第49行/twilio-php-master/Twilio/Rest/Api/V2010/Account/AddressList.php
警告:缺少Twilio \ Rest \ Api \ V2010 \ Account \ AddressList :: create()的参数4,在第26行的/Applications/MAMP/htdocs/taddresses.php中调用,并在/ Applications / MAMP / htdocs中定义第49行/twilio-php-master/Twilio/Rest/Api/V2010/Account/AddressList.php
警告:缺少Twilio \ Rest \ Api \ V2010 \ Account \ AddressList :: create()的参数5,在第26行的/Applications/MAMP/htdocs/taddresses.php中调用,并在/ Applications / MAMP / htdocs中定义第49行/twilio-php-master/Twilio/Rest/Api/V2010/Account/AddressList.php
警告:缺少Twilio \ Rest \ Api \ V2010 \ Account \ AddressList :: create()的参数6,在第26行的/Applications/MAMP/htdocs/taddresses.php中调用,并在/ Applications / MAMP / htdocs中定义第49行/twilio-php-master/Twilio/Rest/Api/V2010/Account/AddressList.php
注意:第54行的/Applications/MAMP/htdocs/twilio-php-master/Twilio/Rest/Api/V2010/Account/AddressList.php中未定义的变量:street
注意:未定义的变量:第55行/Applications/MAMP/htdocs/twilio-php-master/Twilio/Rest/Api/V2010/Account/AddressList.php中的城市
注意:未定义的变量:第56行的/Applications/MAMP/htdocs/twilio-php-master/Twilio/Rest/Api/V2010/Account/AddressList.php中的区域
注意:未定义的变量:第57行的/Applications/MAMP/htdocs/twilio-php-master/Twilio/Rest/Api/V2010/Account/AddressList.php中的postalCode
注意:未定义的变量:第58行的/Applications/MAMP/htdocs/twilio-php-master/Twilio/Rest/Api/V2010/Account/AddressList.php中的isoCountry
致命错误:未捕获的异常&#39; Twilio \ Exceptions \ RestException&#39;消息&#39; [HTTP 400]无法创建记录:必须提供IsoCountry&#39;在/Applications/MAMP/htdocs/twilio-php-master/Twilio/Version.php:85堆栈追踪:#0 /Applications/MAMP/htdocs/twilio-php-master/Twilio/Version.php(207):Twilio \ Version-&gt; exception(对象(Twilio \ Http \ Response),&#39;无法创建...&#39;)#1 / Applications / MAMP / htdocs / twilio-php-master / Twilio / Rest / Api /V2010/Account/AddressList.php(68):Twilio \ Version-&gt; create(&#39; POST&#39;,&#39; / Accounts / AC545 ......&#39;,Array,Array)# 2 /Applications/MAMP/htdocs/taddresses.php(26):Twilio \ Rest \ Api \ V2010 \ Account \ AddressList-&gt; create(Array)#3 {main}抛出/ Applications / MAMP / htdocs / twilio-php第85行的-master / Twilio / Version.php
我使用twilio php api。我能够创建子帐户,搜索新号码,购买号码等等,但地址卡住了!
答案 0 :(得分:0)
Twilio开发者传道者在这里。
我不确定您是使用Twilio PHP helper library的版本4还是版本5,但无论哪种方式,您都会错误地提供参数。您不应该提供参数数组,而应将它们作为位置参数提供。请参阅version 4和version 5源代码。
所以你的代码应该是这样的:
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
// Get the PHP helper library from twilio.com/docs/php/install
require __DIR__ . '/twilio-php-master/Twilio/autoload.php';
use Twilio\Rest\Client;
// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "xxxxx";
$token = "xxxx";
$client = new Client($sid, $token);
$address = $client->addresses->create(
"Customer", "2 rue du chapelier ", "", "France", "75020", "FR"
)
);
?>
如果有帮助,请告诉我。