<?php
// Require the bundled autoload file - the path may need to change
// based on where you downloaded and unzipped the SDK
require_once __DIR__ . '/twilio-php-master/Twilio/autoload.php';
#require __DIR__ . '/var/sip10/public_html/htdocs/twilio/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 = 'ACXXXXXXXXXXXXXXXXXXXXXXXXXX';
$token = 'XXXXXXXXXXXXXXXXXXXXXXX';
$client = new Client($sid, $token);
// Use the client to do fun stuff like send text messages!
$client->messages->create(
'+1XXXXXXXXXX',
array(
'from' => '+1XXXXXXXXXX',
'body' => "Hey Jenny! Good luck on the bar exam!"
)
);
?>
当我尝试向我的手机发送一条消息时,当所有正确的帐户信息都显示 http500 错误时,我测试了该库是否正常工作(是的),我知道它因为 $client->messages- 而变得困惑>创造但不明白为什么。
最佳答案
Twilio PHP 库依靠 cURL 发出 HTTP 请求,这些请求实际上会到达 Twilio 的 API 端点以发送您的消息。
您需要使 cURL 可用于您的 PHP。
- 通过键入
sudo apt-get install curl
安装 cURL - 通过键入
sudo service apache2 restart
重新启动 Apache - 通过键入
sudo apt-get install php5-curl
安装 PHP5 cURL - 通过键入
sudo service apache2 restart
重新启动 Apache
请根据您的情况随意调整以上内容,但主要思想是 PHP 和 Twilio 库还不够,您还需要 cURL。
关于php - 使用 PHP54 和 Twilio 发送消息时出现 Http 500 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40428591/