客户端实例化时未找到类'Twilio \ Rest \ Client'

时间:2017-06-27 16:01:37

标签: php twilio

我正在尝试将Twilio集成到我的应用程序中。当我运行他们的示例代码时,它运行得很好:

require_once "twilio-php-master/Twilio/autoload.php";
use Twilio\Rest\Client;

$AccountSid = "XXXXXX";
$AuthToken = "XXXXXX";

$client = new Client($AccountSid, $AuthToken);

$sms = $client->account->messages->create(
    "+15555555555",
    array(
        'from' => "+15556665566",
        'body' => "Hey, Monkey Party at 6PM. Bring Bananas!"
    )
);

然而,当我尝试将它集成到一个类中时,我每次执行时都会找不到PHP致命错误类'Twilio \ Rest \ Client'。这是我班上的代码:

require_once "twilio-php-master/Twilio/autoload.php";
use Twilio\Rest\Client;

class Customer{
    //constructors etc

    public function sendText(){
        $AccountSid = "XXXXXX";
        $AuthToken = "XXXXXX";

        $client = new Client($AccountSid, $AuthToken);
        $sms = $client->account->messages->create(
            '+15555555555',
            array(
                'from' => "+15556665566",
                'body' => "Hey, Monkey Party at 6PM. Bring Bananas!"
            )
        );
    }
}

我已经检查了Twilio Library中的开始标记,我确保文件位置正确(它会在

时抛出错误)
$client = new Client($AccountSid, $AuthToken);

行被执行,而不是在require_once处执行但是我似乎无法弄清楚出了什么问题。

0 个答案:

没有答案