python - 如何使用 Twilio python 帮助程序来翻阅消息列表?

标签 python list twilio

我正在使用 https://github.com/twilio/twilio-python并通读了文档,包括 https://www.twilio.com/docs/api/rest/response#response-formats-list-paging-information .

我似乎找不到从大型列表中检索下一页的方法。我正在使用以下代码检索初始列表,但不知道如何检索 nextpageuri,然后检索下一页。

client = TwilioRestClient(twilioAccount, twilioToken)

messages = client.messages.list(
    to="+15162047575",
    # to="+15167217331",
    after=date(2014,5,7),
    PageSize=50)

我使用的是 Twilio 3.6.4 和 3.5.1 以及最新版本的 python 助手。

最佳答案

我终于找到了答案(我想我自己回答也没问题......)

Twilio 帮助程序库(至少是 python 帮助程序)不直接公开 nextpageuri(这解释了为什么我找不到访问 nextpageuri 的方法或属性)。

尽管 Twilio 站点上的分页信息描述了使用 nextpageuri 进行分页的方法,但帮助程序库使用的是 iter() 方法。

因此,与其使用我在问题中发布的代码然后遍历“消息”,不如使用:

client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
for message in client.messages.iter():
    # code to process message

来自 python 帮助程序文档(不是 Twilio Rest API 文档):

Sometimes you’d like to retrieve all records from a list resource. Instead of manually paging over the resource, the resources.ListResource.iter method returns a generator. After exhausting the current page, the generator will request the next page of results.

这里有一些引用:

关于python - 如何使用 Twilio python 帮助程序来翻阅消息列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23845177/

相关文章:

node.js - Twilio:Twiml.Gather() 不读取 key

python - 通过降低精度来加速 sympy 求解器?

python - 使用 lxml 解析 HTML 时如何保留 namespace 信息?

python - 使用 python 正则表达式在另一个模式中编译模式

R - 打乱列表并保留元素大小

php - 如何接收发送到 twilio 号码的短信

python 比较 CSV 并找出差异

java - 如何列出所有大于给定参数的文件?

c# - 想知道一种在 C# 中使用 List<> 和结构来节省内存的方法

python - 让真人在 Twilio 中接听电话