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条)

报告相同问题?

悬赏问题

  • ¥15 一道python难题2
  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备