dri8163 2016-09-27 06:00
浏览 53
已采纳

PHP - 如何在作曲家命名空间环境中访问Twilio

I've been working with Rachet WebSockets and created a simple chat application. The example uses a WebSocket namespace. This is my first time using namespace. Now I'm trying to add Twilio service but can seem to add Twilio to my namespace.

I know it is autoloaded in the autoload_files.php

<?php

// autoload_files.php @generated by Composer

$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);

return array(
    $vendorDir . '/twilio/sdk/Services/Twilio.php',
);

In the composer.json file

{
    "autoload": {
        "psr-0": {
            "Websocket": "src"
        }
    },
    "require": {
        "cboden/ratchet": "^0.3.3",
        "twilio/sdk": "^4.5"
    }
}

I followed the steps from this website : https://www.twilio.com/docs/libraries/php#using-without-composer

I'm calling twilio inside a method of my class like this:

$AccountSid = "xxxxxxxxxxxxxxxxx";
$AuthToken = "xxxxxxxxxxxxxxxxx";

$client = new Client($sid, $token);

$message = $client->account->messages->create(array( 
    'To' => "+555555555", 
    'From' => "+555555555", 
    'Body' => "This is a test",   
));

Keep getting this error: Uncaught Error: Class 'Websocket\Client' not found in ......

I'm very new to composer and namespace, hope this is enough information to help me.

  • 写回答

2条回答 默认 最新

  • duangang4940 2016-09-27 14:17
    关注

    I had to update Twilio,

    ran composer require twilio/sd

    - Removing twilio/sdk (4.12.0)
    - Installing twilio/sdk (5.4.1)
    Downloading: 100%         
    

    Now I'm able to use Twilio\Rest\Client; since it was missing before.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向