Insomania Insomania - 1 year ago 41
PHP Question

Not able to retrieve call records from Twilio in Laravel

i am trying to use Twilio in my Laravel project, i have used it's aloha package, it works fine when i try to send messages or to create calls, but when i try to retrieve the call logs then it throw an exception.
here is what i have tried so far:

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


when i try to send message it works:

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) {
}


it also works when i try to create a call:

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();
}


but when i try to read a call it throws an error:

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();
}


the error i get is:

Call to undefined method Services_Twilio_Rest_Calls::read()

Source

Please help me to sort out this issue.

Thanks.

Answer Source

change this line

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

to

$client->account->calls
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download