我使用Vresh Twilio Bundle在Symfony应用程序中使用Twilio-PHP。我从我的帐户中检索了短信,如下所示:
@Component({
selector: 'page-home',
templateUrl: 'app/home.page.html'
})
export class HomePage {
appName = 'Ionic App';
slides: Slides;
public data: MonthViewData[] = [];
public date = new Date(Date.now());
monthNames = ["January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
];
constructor() {
this.data.push({title:'t0'});
this.data.push({title:'t1'});
this.data.push({title:'t2'});
}
slideChanged(slides: Slides) {
this.slides = slides;
return new Promise((resolve, reject) => {
let scrollToNext = this.slides.getActiveIndex() > this.slides.getPreviousIndex();
console.log(this.slides.getActiveIndex(), this.slides.getPreviousIndex());
let currentSlideIndex: number = this.slides.getActiveIndex() - 1;
if (currentSlideIndex > 2) {
currentSlideIndex = 0;
}
if (currentSlideIndex < 0) {
currentSlideIndex = 2;
}
let previousSlideIndex = currentSlideIndex - 1;
let nextSlideIndex = currentSlideIndex + 1;
if (previousSlideIndex < 0) {
previousSlideIndex = 2;
}
if (nextSlideIndex > 2) {
nextSlideIndex = 0;
}
if (this.slides.getActiveIndex() == 1 && this.slides.getPreviousIndex() == 0) {
this.date = new Date(Date.now());
} else {
if (scrollToNext) {
this.date.setMonth(this.date.getMonth() + 1);
} else {
this.date.setMonth(this.date.getMonth() - 1);
}
}
console.log('active month', this.date);
console.log('indexes', previousSlideIndex, '->', currentSlideIndex, '->', nextSlideIndex);
this.data[currentSlideIndex].title = this.monthNames[this.date.getMonth()] + ' ' + this.date.getFullYear();
this.data[previousSlideIndex].title = this.monthNames[this.date.getMonth() - 1] + ' ' + this.date.getFullYear();
this.data[nextSlideIndex].title = this.monthNames[this.date.getMonth() + 1] + ' ' + this.date.getFullYear();
})
}
}
这会为我提供帐户中每条消息的列表。我希望能够在API调用时对其进行过滤,以仅检索具有特定方向的消息,或者在特定日期之后。
在Twilio docs中,有一个使用
的示例$twilio = $this->container->get('twilio.api');
$messages = $twilio->account->messages
...但$params = array('DateSent' => '2017-10-20');
$messages = $twilio->account->messages->read($params);
方法对我来说并不存在。
read()
有人可以建议如何从Twilio检索邮件,并在通话时按参数过滤它们吗?
答案 0 :(得分:0)
您正在查看版本不正确的文档:您在项目中使用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;
}
答案 1 :(得分:0)
Twilio开发者传道者在这里。
正如迈克尔指出的那样,您使用的是Twilio PHP library版本4。理想情况下,您可以升级到版本5,但如果您想坚持使用Vresh Twilio Bundle,那么您目前只能使用版本4。
您可以使用此版本的库过滤邮件。文档也存在于GitHub中,因此您可以看到how to use the Messages resource with Twilio PHP 4。要过滤消息,您需要getIterator
方法,您可以像这样使用它:
foreach ($client->account->messages->getIterator(0, 50, array(
'DateSent>' => '2017-10-20',
)) as $message) {
// use $message
}
您无法按方向过滤only To
, From
and DateSent
。