我正在使用 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/