【发布时间】:2017-06-14 04:40:36
【问题描述】:
我正在尝试使用 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
));
它给了我这个错误:
致命错误:在第 9 行的 /home/vhosts/xxxx.xxxx.com/twilio/sms.php 中找不到类“Twilio\Rest\Client”
我也试过这段代码,但没有用:
<?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(): 无法打开所需的 '/home/vhosts/xxxx.xxxxx.com/twilio/Twilio/Version.php' (include_path='.:/usr/share/pear:/usr/share /php') 在 /home/vhosts/xxxx.xxxx.com/twilio/Twilio/autoload.php 第 140 行
【问题讨论】:
-
您是否使用自动加载器(即您使用 composer 获得的)?
-
不,我没有使用 composer 我直接使用 twilio-php 源代码
-
您需要某种自动加载器,以便 PHP 知道在哪里可以找到 Twilio 文件。我强烈建议使用 composer 安装 twilio-php,因为它会为你设置好一切
-
尝试包含php类或自动加载器(如果有)
-
我试过了,请看主帖看看错误
标签: php twilio-php