I am using this code in PHP to list SMS messages received to a certain number:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Get the PHP helper library from twilio.com/docs/php/install
require_once('twilio/Services/Twilio.php'); // Loads the library
// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "";
$token = "";
$client = new Services_Twilio($sid, $token);
$messages = $client->account->messages->getIterator(0, 50, array(
'To' => $_SERVER['QUERY_STRING']
));
foreach ($messages as $message) {
echo "<tr><td>" . $message->from . "</td><td>" . $message->date_sent . "</td><td>" . $message->body . "</td></tr>";
}
?>
but it is outputting this error message:
Warning: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in /var/www/temp-sms.com/twilio/Services/Twilio/HttpStream.php on line 67
Warning: file_get_contents(): Failed to enable crypto in /var/www/temp-sms.com/twilio/Services/Twilio/HttpStream.php on line 67
Warning: file_get_contents(https://api.twilio.com/2010-04-01/Accounts/AC049b65c32bd0cad6a229b44719ac6116/Messages.json?Page=0&PageSize=50&To=%2B16466635449): failed to open stream: operation failed in /var/www/temp-sms.com/twilio/Services/Twilio/HttpStream.php on line 67
Fatal error: Uncaught exception 'Services_Twilio_HttpStreamException' with message 'Unable to connect to service' in /var/www/temp-sms.com/twilio/Services/Twilio/HttpStream.php:70 Stack trace: #0 [internal function]: Services_Twilio_HttpStream->__call('get', Array) #1 [internal function]: Services_Twilio_HttpStream->get('/2010-04-01/Acc...') #2 /var/www/temp-sms.com/twilio/Services/Twilio.php(260): call_user_func_array(Array, Array) #3 /var/www/temp-sms.com/twilio/Services/Twilio.php(236): Base_Services_Twilio->_makeIdempotentRequest(Array, '/2010-04-01/Acc...', 1) #4 /var/www/temp-sms.com/twilio/Services/Twilio/ListResource.php(125): Base_Services_Twilio->retrieveData('/2010-04-01/Acc...', Array) #5 /var/www/temp-sms.com/twilio/Services/Twilio/ListResource.php(179): Services_Twilio_ListResource->getPage(0, 50, Array, NULL) #6 [internal function]: Services_Twilio_ListResource->getPageGenerator(0, 50, Array, NULL) #7 /var/www/temp-sms.com/twilio/Services/Twilio/AutoPagingIterator.php(104): call_user_func_array(Array, Array in /var/www/temp-sms.com/twilio/Services/Twilio/HttpStream.php on line 70
Update
Installed php5-curl
as suggested by @philnash and restarted.
New error message:
Fatal error: Uncaught exception 'Services_Twilio_TinyHttpException' with message 'SSL certificate problem: self signed certificate in certificate chain' in /var/www/temp-sms.com/twilio/Services/Twilio/TinyHttp.php:119 Stack trace: #0 [internal function]: Services_Twilio_TinyHttp->__call('get', Array) #1 [internal function]: Services_Twilio_TinyHttp->get('/2010-04-01/Acc...') #2 /var/www/temp-sms.com/twilio/Services/Twilio.php(260): call_user_func_array(Array, Array) #3 /var/www/temp-sms.com/twilio/Services/Twilio.php(236): Base_Services_Twilio->_makeIdempotentRequest(Array, '/2010-04-01/Acc...', 1) #4 /var/www/temp-sms.com/twilio/Services/Twilio/ListResource.php(125): Base_Services_Twilio->retrieveData('/2010-04-01/Acc...', Array) #5 /var/www/temp-sms.com/twilio/Services/Twilio/ListResource.php(179): Services_Twilio_ListResource->getPage(0, 50, Array, NULL) #6 [internal function]: Services_Twilio_ListResource->getPageGenerator(0, 50, Array, NULL) #7 /var/www/temp-sms.com/twilio/Services/Twilio/AutoPagingIterator.php(104): in /var/www/temp-sms.com/twilio/Services/Twilio/TinyHttp.php on line 119
Twilio developer evangelist here.
This is a similar question to this one, so I have replicated the answer here. However, it may be better for StackOverflow's rules to close this as a duplicate.
--
I found this happened when you don't have the curl bindings for PHP. Try recompiling PHP with curl or installing the php5-curl package.
Let me know if that helps at all.
[edit]
If you find you are now getting an error regarding self signed certificates you will want to follow the advice available in the Twilio PHP FAQ.