我试图使用twilio php api。
这是我的代码:
<?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
));
它给了我这个错误:
致命错误:Class&#39; Twilio \ Rest \ Client&#39;在第9行的/home/vhosts/xxxx.xxxx.com/twilio/sms.php中找不到
我也试过这段代码并且没有工作:
<?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
));
它给了我这个错误:
致命错误:require():无法打开所需&#39; /home/vhosts/xxxx.xxxxx.com/twilio/Twilio/Version.php' (include_path =&#39;。:/ usr / share / pear:/ usr / share / php&#39;)在第140行的/home/vhosts/xxxx.xxxx.com/twilio/Twilio/autoload.php中
答案 0 :(得分:6)
将这一行放在最开头:
use Twilio\Rest\Client;
然后添加您的include语句:
require_once "Twilio/autoload.php";