我試圖創建一個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();
?>
我的服務器有php 5.2 –
PHP Namespacing是在PHP 5.3中引入的; PHP 5.2已經超過6年正式報廢了,也許你應該考慮升級 –