2016-11-04 27 views
3
<?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->創建而變得混亂,但無法理解爲什麼。HTTP 500錯誤發送使用PHP54和Twilio

+0

你能發佈你得到確切的錯誤消息嗎? – philnash

+0

歡迎來到Stack Overflow Mandeep!你確定Twilio確實能夠訪問你的服務器嗎? https://www.twilio.com/blog/2015/09/6-awesome-reasons-to-use-ngrok-when-testing-webhooks.html –

回答

2

Twilio PHP庫依靠cURL使實際上擊中Twilio的API端點的HTTP請求發送消息。

您需要將cURL提供給您的PHP。

  • 通過鍵入sudo apt-get install curl
  • 重啓Apache通過鍵入sudo service apache2 restart
  • 通過鍵入sudo apt-get install php5-curl
  • 重啓Apache安裝PHP5捲曲通過鍵入sudo service apache2 restart

隨意調整上面安裝捲曲你的情況,但主要想法是PHP和Twilio庫不夠用,你還需要cURL。