twilio'未知的上下文帐户

时间:2017-03-07 02:11:25

标签: php twilio

我正在尝试通过Twilio发送简单的短信和Php,但我得到了这个致命错误,

  

带有消息的未捕获异常'Twilio \ Exceptions \ TwilioException'   '未知的上下文帐户'   C:\ XAMPP \ htdocs中\ Twilio \厂商\ twilio \ SDK \ Twilio \休息\ Client.php:687

     

堆栈追踪:

     

0 C:\ xampp \ htdocs \ Twilio \ twilio.php(24):Twilio \ Rest \ Client-> __ call('accounts',Array)

     

1 C:\ xampp \ htdocs \ Twilio \ twilio.php(24):Twilio \ Rest \ Client-> accounts('AC8687f4eaba8c6 ...')

     

2 {main}投入   C:\ xampp \ htdocs \ Twilio \ vendor \ twilio \ sdk \ Twilio \ Rest \ Client.php on   第687行

这是我的本地服务器代码:

<?php 
    // Get the PHP helper library from twilio.com/docs/php/install 
    require_once 'vendor/autoload.php'; // Loads the library 
    use Twilio\Rest\Client; 
    $account_sid = 'AC8687f4eaba8c68XXXXXXXXXXXXX'; 
    $auth_token = '6baf210351f27a38850XXXXXXXXXXXXXXXX'; 
    $client = new Client($account_sid, $auth_token); 
    $messages = $client->accounts('AC8687f4eaXXXXXXXXXXX') 
    ->messages->create('+52722XXXXXXX', array( 
         'From' => '+151240XXXXX',        
    ));
?>

1 个答案:

答案 0 :(得分:5)

Twilio开发者传道者在这里。

看起来好像是在尝试从您首先授权PHP库的帐户发送消息。在这种情况下,您无需先调用帐户资源。这可能是故意遗漏,但我也注意到你的信息没有遗嘱。

以下代码适合您:

<?php 
    // Get the PHP helper library from twilio.com/docs/php/install 
    require_once 'vendor/autoload.php'; // Loads the library 
    use Twilio\Rest\Client; 
    $account_sid = 'AC8687f4eaba8c68XXXXXXXXXXXXX'; 
    $auth_token = '6baf210351f27a38850XXXXXXXXXXXXXXXX'; 
    $client = new Client($account_sid, $auth_token); 
    $messages = $client->messages->create('+52722XXXXXXX', array( 
         'From' => '+151240XXXXX',
         'Body' => 'Hello from my PHP code!'
    ));
?>