无法在Laravel

时间:2017-05-23 06:00:43

标签: php laravel-5 twilio

我正在尝试在我的Laravel项目中使用Twilio,我已经使用了它的aloha包。当我尝试发送消息或创建调用时,它工作正常,但是当我尝试检索调用日志时,它会抛出异常。

这是我到目前为止所尝试的内容:

    $AccountSid = <ACCOUNT ID>;
    $AuthToken = <AUTH TOKEN>;
    $client = new \Services_Twilio($AccountSid, $AuthToken);

当我尝试发送消息时,它可以工作:

        try{
            $sms_content="";
            $sms_content .="Amy has requested a quote for her wedding."."\n\n";
            $sms_content .="";

            $sms = $client->account->messages->sendMessage(
                    <FROM NUMBER>, 
                    <TO NUMBER>,
                    $sms_content
                );  
        } 
        catch (Exception $e) {
        }

当我尝试创建呼叫时,它也有效:

        try {
            // Initiate a new outbound call
            $call = $client->account->calls->create(
                // to call.
                <FROM NUMBER>,
                <TO NUMBER>,
                array("url" => "http://demo.twilio.com/welcome/voice/")
            );
            echo "Started call: " . $call->sid;
        } catch (Exception $e) {
            echo "Error: " . $e->getMessage();
        }

但是当我尝试阅读一个电话时,它会抛出一个错误:

        try {
            // Get Recent Calls
            foreach ($client->account->calls->read() as $call) {
                $time = $call->startTime->format("Y-m-d H:i:s");
                echo "Call from $call->from to $call->to at $time of length $call->duration \n";
            }
        } catch (Exception $e) {
            echo "Error: " . $e->getMessage();
        }

我得到的错误是:

  

调用未定义的方法Services_Twilio_Rest_Calls :: read()

Source

1 个答案:

答案 0 :(得分:2)

更改此行

$client->account->calls->read()

$client->account->calls