我在使用Vresh Twilio Bundle的Symfony应用程序中使用Twilio。我从我的帐户中检索短信如下:
$twilio = $this->container->get('twilio.api');
$messages = $twilio->account->messages这给我一个帐户中每条信息的列表。我希望能够在API调用的点上过滤它,只检索具有特定方向的消息,或者在某个日期之后检索消息。
在吐里奥博士中,有一个示例使用
$params = array('DateSent' => '2017-10-20');
$messages = $twilio->account->messages->read($params);...but read()方法对我来说并不存在。
[Symfony\Component\Debug\Exception\UndefinedMethodException]
Attempted to call an undefined method named "read" of class "Services_Twilio_Rest_Messages".有人能建议如何从Twilio检索消息,并在调用点通过参数过滤消息吗?
发布于 2017-10-26 23:54:09
两位开发人员在这里传道。
正如Michael所指出的,您使用的是Twilio PHP库的第4版。理想情况下,您可以升级到版本5,但是如果您想继续使用,那么您目前只能使用版本4。
不过,您可以使用此版本的库筛选消息。这些文档也存在于GitHub中,因此您可以看到如何使用Twilio 4使用消息资源。要筛选消息,您需要getIterator方法,您可以这样使用它:
foreach ($client->account->messages->getIterator(0, 50, array(
'DateSent>' => '2017-10-20',
)) as $message) {
// use $message
}你不能按方向过滤,DateSent。
发布于 2017-10-26 06:09:46
您正在查看不正确版本的文档:在项目中使用4.x版本,但查看5.x文档。
在链接到的页面上有4.x版本的示例:
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library
// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
$token = "your_auth_token";
$client = new Services_Twilio($sid, $token);
// Loop over the list of messages and echo a property for each one
foreach ($client->account->messages as $message) {
echo $message->body;
}https://stackoverflow.com/questions/46932326
复制相似问题