2017-01-19 34 views
-1

我試圖創建一個Twilio令牌生成和我的項目返回此錯誤:Twilio PHP的「使用」返回一個錯誤意外T_STRING

Parse error: syntax error, unexpected T_STRING, expecting T_CONSTANT_ENCAPSED_STRING or '(' in file dir on line 8

8號線中有use Twilio\Rest\Client;。我安裝了PHP Twilio SDK,這是我唯一的錯誤。

問題是:此SDK中的幾乎所有文件都有use ...措辭。我爲此做了什麼來正常工作?

我的文件VTC.php做到這一點:

<?php 

// Required if your environment does not handle autoloading 
require __DIR__ . '/vendor/autoload.php'; 

// Use the REST API Client to make requests to the Twilio REST API 
use Twilio\Rest\Client; 

$id = $_GET['id']; 


// Substitute your Twilio AccountSid and ApiKey details 
$accountSid = 'xxx'; 
$apiKeySid = 'xxx'; 
$apiKeySecret = 'xxx'; 

// Create an Access Token 
$token = new Services_Twilio_AccessToken(
    $accountSid, 
    $apiKeySid, 
    $apiKeySecret, 
    $ttl=3600, 
    $identity='user'.$id 
); 

// Grant access to Conversations 
$grant = new Services_Twilio_Auth_ConversationsGrant(); 
$grant->setConfigurationProfileSid('configurationProfileSid'); 
$token->addGrant($grant); 

// Serialize the token as a JWT 
echo $token->toJWT(); 
?> 
+0

我的服務器有php 5.2 –

+1

PHP Namespacing是在PHP 5.3中引入的; PHP 5.2已經超過6年正式報廢了,也許你應該考慮升級 –

回答

2

PHP 5.2太低運行您正在使用的庫。假設您使用的是this library,composer.jsonhere)表示最低版本爲5.3。

我會提醒你,雖然5.6目前是PHP的oldest supported version

+0

我想這個..是我的虛擬主機的默認版本。我試着更新5.6並重試。 THKS! –

+0

如果他們提供5.2作爲默認,我不會使用您的虛擬主機。如果他們如此落後,誰知道他們如何處理你的信用卡數據和密碼......我會建議找到一個更有信譽的虛擬主機。 – Scopey

+0

我現在更新我的php 5.6。在我的phpadmin我看到這個: PHP版本:5.6.29-0 + deb8u1和錯誤繼續... 更好奇的是,如果我使用phpinfo()函數它告訴我,PHP是5.2 –

相關問題