Class 'Twilio\Rest\Client' not found

天大地大妈咪最大 提交于 2020-01-14 14:48:30

问题


I'm trying to use twilio php api .

This is my code:

        <?php
    $sid = "xxxxxx"; 
    $token = "xxxxxxx"; 

    $phone=$_POST["phone"];
    $code=$_POST["code"];

    $client = new Twilio\Rest\Client($sid, $token);
    $message = $client->messages->create(
      $phone, 
      array(
        'from' => 'xxxxxxx', 

   'body' => $code
  ));

It gives me this error :

Fatal error: Class 'Twilio\Rest\Client' not found in /home/vhosts/xxxx.xxxx.com/twilio/sms.php on line 9

I've also tried this code and didn't work:

     <?php
    $sid = "xxxxxxx"; 
    $token = "xxxxxxxx"; 


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

      $phone=$_POST["phone"];
       $code=$_POST["code"];

    $client = new Client($sid, $token);
    $message = $client->messages->create(
  $phone, 
  array(
    'from' => 'xxxxx', 
    'body' => $code
  ));

It gives me this error :

Fatal error: require(): Failed opening required '/home/vhosts/xxxx.xxxxx.com/twilio/Twilio/Version.php' (include_path='.:/usr/share/pear:/usr/share/php') in /home/vhosts/xxxx.xxxx.com/twilio/Twilio/autoload.php on line 140


回答1:


put this line at the very beginning:

use Twilio\Rest\Client;

then add your include statement:

require_once "Twilio/autoload.php";


来源:https://stackoverflow.com/questions/41911927/class-twilio-rest-client-not-found

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!