Twilio PHP致命错误

时间:2017-03-14 15:14:18

标签: php twilio

所以我一直在免费的网络托管服务器上测试twilio,这就是我得到的:

Fatal error: Class 'Twilio\Rest\Api' not found in /home/u512189195/public_html/twilio-php-master/Twilio/Rest/Client.php on line 263

这是我的代码:

    <?php
// Require the bundled autoload file - the path may need to change
// based on where you downloaded and unzipped the SDK
require __DIR__ . '/twilio-php-master/Twilio/autoload.php';

// Use the REST API Client to make requests to the Twilio REST API
use Twilio\Rest\Client;

// Your Account SID and Auth Token from twilio.com/console
$sid = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$token = 'your_auth_token';
$client = new Client($sid, $token);

// Use the client to do fun stuff like send text messages!
$client->messages->create(
    // the number you'd like to send the message to
    '+15558675309',
    array(
        // A Twilio phone number you purchased at twilio.com/console
        'from' => '+15017250604',
        // the body of the text message you'd like to send
        'body' => "Hey Jenny! Good luck on the bar exam!"
    )
);
?>

我还试过没有__DIR__ .

显然,我已经用我自己的数据替换了变量。

我已经上传了我们从twilio文档网站获得的php主库。 - https://www.twilio.com/docs/libraries/php

2 个答案:

答案 0 :(得分:0)

您可以通过composer

安装twilio包

https://packagist.org/packages/twilio/sdk

然后;

<?php 
require __DIR__ . '/vendor/autoload.php';

...

use Twilio\Rest\Client;
...

答案 1 :(得分:0)

您应该检查您下载的库中是否存在该类。 寻找:

twilio-php-master/Twilio/Rest/Api.php

如果缺少(这就是你得到的错误信息),那么你需要下载更新版本的帮助库。

请参阅&#39;使用不使用编辑器&#39; here