Twilio 如何对消息进行分页? [英] Twilio How to do pagination with messages?

查看:60
本文介绍了Twilio 如何对消息进行分页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够从新的 php 客户端获取消息.如何对消息进行分页?如何获取next_uri、first_uri、page_size参数?

I am able to get the messages from the new php client. How do I do pagination with messages? How to get next_uri, first_uri, page_size parameters ?

 <?php 
 require_once '/Twilio/autoload.php'; // Loads the library

 use Twilio\Rest\Client;

 // Your Account Sid and Auth Token from twilio.com/user/account
 $sid = "xxx"; 
 $token = "xxx";
 $client = new Client($sid, $token);

 // Loop over the list of messages and echo a property for each one
 foreach ($client->messages->read() as $message) {
 echo $message->body;
 }
 ?>

推荐答案

Twilio 开发人员布道者在这里.

Twilio developer evangelist here.

您可以使用 stream() 它将为您的消息返回一个迭代器.你可以给 stream() 一个限制,但默认情况下它没有限制并且会遍历你的所有消息.

Instead of using read() you can use stream() which will return an iterator for your messages. You can give stream() a limit, but by default it has no limit and will iterate over all of your messages.

 <?php 
 require_once '/Twilio/autoload.php'; // Loads the library

 use Twilio\Rest\Client;

 // Your Account Sid and Auth Token from twilio.com/user/account
 $sid = "xxx"; 
 $token = "xxx";
 $client = new Client($sid, $token);

 // Loop over the list of messages and echo a property for each one
 foreach ($client->messages->stream() as $message) {
 echo $message->body;
 }
 ?>

分页信息本身在每个请求中返回.您可以看到示例调用Calls 文档中的资源Messages 的分页信息将相同.

The pagination information itself is returned in each request. You can see an example of a call to the Calls resource in the documentation and the pagination information will be the same for Messages.

这篇关于Twilio 如何对消息进行分页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆